Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.elumen.jpa.workflow.course;
- import com.elumen.dto.course.AdditionalSystemFieldDto;
- import com.elumen.jpa.converters.JsonElementConverter;
- import com.elumen.jpa.converters.workflow.course.AdditionalSystemFieldValueConverter;
- import com.elumen.jpa.user.Role;
- import com.elumen.jpa.user.Subrole;
- import com.elumen.jpa.user.User;
- import com.elumen.services.curriculum.domain.CourseDTO;
- import com.google.gson.Gson;
- import com.google.gson.JsonElement;
- import com.google.gson.JsonObject;
- import com.google.gson.annotations.Expose;
- import org.apache.commons.lang3.StringUtils;
- import javax.persistence.Column;
- import javax.persistence.Convert;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- import javax.persistence.JoinColumn;
- import javax.persistence.OneToOne;
- import javax.persistence.Table;
- import javax.persistence.Transient;
- import java.util.Date;
- import java.util.List;
- import java.util.UUID;
- /**
- * @author Augusto Amarilla
- * @since 6.5
- */
- @Entity
- @Table(name = "course_workflow_json_history")
- public class CourseWorkflowJsonHistory {
- public static final String JSONLATESTVERSION = "1.7";
- @Id
- @Expose
- @GeneratedValue(strategy = GenerationType.AUTO)
- @Column(name = "course_workflow_json_history_id")
- private Integer courseWorkflowJsonHistoryId;
- @Expose
- @Column(name = "author_user_id")
- private Integer authorUserId;
- @OneToOne
- @Expose
- @JoinColumn(name = "author_user_id", insertable = false, updatable = false)
- private User authorUser;
- @Expose
- @Column(name = "author_role_id")
- private Integer authorRoleId;
- @OneToOne
- @Expose
- @JoinColumn(name = "author_role_id", insertable = false, updatable = false)
- private Role authorRole;
- @Expose
- @Column(name = "author_subrole_id")
- private Integer authorSubroleId;
- @OneToOne
- @Expose
- @JoinColumn(name = "author_subrole_id", insertable = false, updatable = false)
- private Subrole authorSubrole;
- @Expose
- @Column(name = "json_object_id")
- private String jsonObjectId;
- @Expose
- @Column(name = "lst_mod_date")
- private Date lastModificationDate;
- @Expose
- @Column(name = "json_data")
- @Convert(converter = JsonElementConverter.class)
- private JsonElement jsonData;
- @Expose
- @Column(name = "json_data",insertable = false,updatable = false)
- @Convert(converter = CourseDtoConverter.class)
- private CourseDTO courseDto;
- @Expose
- @Column(name = "workflow_type")
- private String workflowType;
- @Expose
- @Column(name = "parent_json_object_id")
- private String parentJsonObjectId;
- @Expose
- @Column(name = "workflow_uuid")
- private String workflowUUID;
- @Expose
- @Column(name = "chair_report_id")
- private Integer chairReportId;
- @Expose
- @Column(name = "done")
- private Boolean done = false;
- @Expose
- @Column(name = "template_id")
- private Integer templateId;
- @Expose
- @Column(name = "committee_approval_date")
- private Date committeeApprovalDate;
- @Expose
- @Column(name = "org_id")
- private Long orgId;
- @Expose
- @Column(name = "code")
- private String code;
- @Expose
- @Column(name = "name")
- private String name;
- @Column(name = "additional_system_field")
- @Convert(converter = AdditionalSystemFieldValueConverter.class)
- private AdditionalSystemFieldWrapper additionalSystemFieldWrapper;
- @Transient
- @Expose
- private List<AdditionalSystemFieldDto> additionalSystemFieldList;
- public CourseWorkflowJsonHistory() {
- //Empty constructor
- this.additionalSystemFieldList = additionalSystemFieldWrapper.getAdditionalSystemFieldDtoList();
- }
- /**
- * <p>Constructs an instance of {@link CourseWorkflowJsonHistory}</p>
- * <p>The {@code jsonObjectId} is generated concatenating a new random UUID and the current date in milliseconds</p>
- * <p>If the {@code lastModificationDate} is {@link null} the current date is used ({@code new Date()})</p>
- *
- * @param userId User ID
- * @param roleId Role ID
- * @param subroleId Subrole ID
- * @param lastModificationDate Last Modification Date
- * @param jsonData Course JsonData
- * @param workflowType Workflow Type
- * @param parentJsonObjectId Parent Json Object ID
- * @param tempalteId Workflow Template Id
- * @param orgId Id of the org entity for the base course
- * @param code code of the base course
- * @param name name of the base course
- */
- public CourseWorkflowJsonHistory(
- Integer userId,
- Integer roleId,
- Integer subroleId,
- Date lastModificationDate,
- JsonElement jsonData,
- String workflowType,
- String parentJsonObjectId,
- Integer tempalteId,
- Long orgId,
- String code,
- String name
- ) {
- this.jsonObjectId = UUID.randomUUID().toString() + new Date().getTime();
- this.authorUserId = userId;
- this.authorRoleId = roleId;
- if (subroleId != null && subroleId != 0) {
- this.authorSubroleId = subroleId;
- }
- if (lastModificationDate == null) {
- this.lastModificationDate = new Date();
- } else {
- this.lastModificationDate = lastModificationDate;
- }
- this.jsonData = jsonData;
- this.workflowType = workflowType;
- this.parentJsonObjectId = parentJsonObjectId;
- if (StringUtils.isBlank(parentJsonObjectId)) {
- this.parentJsonObjectId = this.jsonObjectId;
- } else {
- this.parentJsonObjectId = parentJsonObjectId;
- }
- this.templateId = tempalteId;
- this.orgId = orgId;
- this.code = code;
- this.name = name;
- }
- public Integer getCourseWorkflowJsonHistoryId() {
- return courseWorkflowJsonHistoryId;
- }
- public void setCourseWorkflowJsonHistoryId(Integer courseWorkflowJsonHistoryId) {
- this.courseWorkflowJsonHistoryId = courseWorkflowJsonHistoryId;
- }
- public Integer getAuthorUserId() {
- return authorUserId;
- }
- public void setAuthorUserId(Integer authorUserId) {
- this.authorUserId = authorUserId;
- }
- public User getAuthorUser() {
- return authorUser;
- }
- public void setAuthorUser(User authorUser) {
- this.authorUser = authorUser;
- }
- public Integer getAuthorRoleId() {
- return authorRoleId;
- }
- public void setAuthorRoleId(Integer authorRoleId) {
- this.authorRoleId = authorRoleId;
- }
- public Role getAuthorRole() {
- return authorRole;
- }
- public void setAuthorRole(Role authorRole) {
- this.authorRole = authorRole;
- }
- public Integer getAuthorSubroleId() {
- return authorSubroleId;
- }
- public void setAuthorSubroleId(Integer authorSubroleId) {
- this.authorSubroleId = authorSubroleId;
- }
- public Subrole getAuthorSubrole() {
- return authorSubrole;
- }
- public void setAuthorSubrole(Subrole authorSubrole) {
- this.authorSubrole = authorSubrole;
- }
- public String getJsonObjectId() {
- return jsonObjectId;
- }
- public void setJsonObjectId(String jsonObjectId) {
- this.jsonObjectId = jsonObjectId;
- }
- public Date getLastModificationDate() {
- return lastModificationDate;
- }
- public void setLastModificationDate(Date lastModificationDate) {
- this.lastModificationDate = lastModificationDate;
- }
- /**
- * Do not use this method. Use {@link CourseWorkflowJsonHistory#getJsonDataNormalized()}
- * @return json data
- * @deprecated Use {@link CourseWorkflowJsonHistory#getJsonDataNormalized()}
- */
- @Deprecated
- public JsonElement getJsonData() {
- return jsonData;
- }
- public void setJsonData(JsonElement jsonData) {
- this.jsonData = jsonData;
- }
- public String getWorkflowType() {
- return workflowType;
- }
- public void setWorkflowType(String workflowType) {
- this.workflowType = workflowType;
- }
- public String getParentJsonObjectId() {return parentJsonObjectId; }
- public void setParentJsonObjectId(String parentJsonObjectId) { this.parentJsonObjectId = parentJsonObjectId; }
- public Boolean getDone() {
- return done;
- }
- public void setDone(Boolean done) {
- this.done = done;
- }
- public Integer getTemplateId() {
- return templateId;
- }
- public void setTemplateId(Integer templateId) {
- this.templateId = templateId;
- }
- /**
- * @return An UUID object from the string field stored in database,
- * if no string stored null is returned
- */
- public UUID getWorkflowUUID() {
- if (StringUtils.isNotBlank(workflowUUID)) {
- return UUID.fromString(this.workflowUUID);
- } else {
- return null;
- }
- }
- /**
- * @param workflowUUID is an UUID object that if not null will be
- * represented as string and store that representation in the
- * Bean property
- */
- public void setWorkflowUUID(UUID workflowUUID) {
- if (workflowUUID != null) {
- this.workflowUUID = workflowUUID.toString();
- } else {
- this.workflowUUID = null;
- }
- }
- public JsonElement getJsonDataNormalized() {
- if (jsonData == null) {
- return null;
- }
- JsonObject data = jsonData.getAsJsonObject();
- if (data.has("version") && JSONLATESTVERSION.equals(data.get("version").getAsString())) {
- return jsonData;
- } else {
- CourseWorkflowJsonUpdateService updateService = new CourseWorkflowJsonUpdateService();
- return updateService.getAsLatest(data);
- }
- }
- // Adding no sonar since it's auto-generated code
- @Override
- public boolean equals(Object o) {//NOSONAR
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- CourseWorkflowJsonHistory that = (CourseWorkflowJsonHistory) o;
- if (!courseWorkflowJsonHistoryId.equals(that.courseWorkflowJsonHistoryId)) {
- return false;
- }
- if (!authorUserId.equals(that.authorUserId)) {
- return false;
- }
- if (authorUser != null ? !authorUser.equals(that.authorUser) : (that.authorUser != null)) {
- return false;
- }
- if (!authorRoleId.equals(that.authorRoleId)) {
- return false;
- }
- if (authorRole != null ? !authorRole.equals(that.authorRole) : (that.authorRole != null)) {
- return false;
- }
- if (authorSubroleId != null ? !authorSubroleId.equals(that.authorSubroleId) : (that.authorSubroleId != null)) {
- return false;
- }
- if (authorSubrole != null ? !authorSubrole.equals(that.authorSubrole) : (that.authorSubrole != null)) {
- return false;
- }
- if (!jsonObjectId.equals(that.jsonObjectId)) {
- return false;
- }
- if (!lastModificationDate.equals(that.lastModificationDate)) {
- return false;
- }
- if (!jsonData.equals(that.jsonData)) {
- return false;
- }
- return true;
- }
- @Override
- public int hashCode() {
- int result = courseWorkflowJsonHistoryId.hashCode();
- result = 31 * result + authorUserId.hashCode();
- result = 31 * result + (authorUser != null ? authorUser.hashCode() : 0);
- result = 31 * result + authorRoleId.hashCode();
- result = 31 * result + (authorRole != null ? authorRole.hashCode() : 0);
- result = 31 * result + (authorSubroleId != null ? authorSubroleId.hashCode() : 0);
- result = 31 * result + (authorSubrole != null ? authorSubrole.hashCode() : 0);
- result = 31 * result + jsonObjectId.hashCode();
- result = 31 * result + lastModificationDate.hashCode();
- result = 31 * result + jsonData.hashCode();
- return result;
- }
- /**
- * Performs a clone of the object returning a new instance of it
- *
- * @return Cloned CourseWorkflowJsonHistory without Id
- */
- public CourseWorkflowJsonHistory copyNoId() {
- CourseWorkflowJsonHistory newHistory = new CourseWorkflowJsonHistory();
- Gson gson = new Gson();
- newHistory.setJsonData(gson.fromJson(gson.toJson(jsonData, JsonElement.class), JsonElement.class));
- newHistory.setLastModificationDate(lastModificationDate);
- newHistory.setAuthorRole(authorRole);
- newHistory.setAuthorRoleId(authorRoleId);
- newHistory.setAuthorSubrole(authorSubrole);
- newHistory.setAuthorSubroleId(authorSubroleId);
- newHistory.setJsonObjectId(jsonObjectId);
- newHistory.setParentJsonObjectId(parentJsonObjectId);
- newHistory.setWorkflowType(workflowType);
- newHistory.setAuthorUser(authorUser);
- newHistory.setAuthorUserId(authorUserId);
- newHistory.setChairReportId(chairReportId);
- newHistory.setTemplateId(templateId);
- newHistory.setDone(done);
- newHistory.setName(name);
- newHistory.setCode(code);
- newHistory.setOrgId(orgId);
- newHistory.setCommitteeApprovalDate(committeeApprovalDate);
- if (workflowUUID != null) {
- newHistory.setWorkflowUUID(UUID.fromString(workflowUUID));
- }else {
- newHistory.setWorkflowUUID(UUID.randomUUID());
- }
- return newHistory;
- }
- public Integer getChairReportId() {
- return chairReportId;
- }
- public void setChairReportId(Integer chairReportId) {
- this.chairReportId = chairReportId;
- }
- public Date getCommitteeApprovalDate() {
- return committeeApprovalDate;
- }
- public void setCommitteeApprovalDate(Date committeeApprovalDate) {
- this.committeeApprovalDate = committeeApprovalDate;
- }
- public Long getOrgId() {
- return orgId;
- }
- public void setOrgId(Long orgId) {
- this.orgId = orgId;
- }
- public String getCode() {
- return code;
- }
- public void setCode(String code) {
- this.code = code;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public CourseDTO getCourseDto() {
- return courseDto;
- }
- public void setCourseDto(CourseDTO courseDto) {
- this.courseDto = courseDto;
- }
- public List<AdditionalSystemFieldDto> getAdditionalSystemFieldList() {
- return additionalSystemFieldList;
- }
- public void setAdditionalSystemFieldList(List<AdditionalSystemFieldDto> additionalSystemFieldDtoList) {
- this.additionalSystemFieldWrapper = new AdditionalSystemFieldWrapper();
- this.additionalSystemFieldWrapper.setAdditionalSystemFieldDtoList(additionalSystemFieldDtoList);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement