Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 15.35 KB | None | 0 0
  1. package com.elumen.jpa.workflow.course;
  2.  
  3. import com.elumen.dto.course.AdditionalSystemFieldDto;
  4. import com.elumen.jpa.converters.JsonElementConverter;
  5. import com.elumen.jpa.converters.workflow.course.AdditionalSystemFieldValueConverter;
  6. import com.elumen.jpa.user.Role;
  7. import com.elumen.jpa.user.Subrole;
  8. import com.elumen.jpa.user.User;
  9. import com.elumen.services.curriculum.domain.CourseDTO;
  10. import com.google.gson.Gson;
  11. import com.google.gson.JsonElement;
  12. import com.google.gson.JsonObject;
  13. import com.google.gson.annotations.Expose;
  14. import org.apache.commons.lang3.StringUtils;
  15.  
  16. import javax.persistence.Column;
  17. import javax.persistence.Convert;
  18. import javax.persistence.Entity;
  19. import javax.persistence.GeneratedValue;
  20. import javax.persistence.GenerationType;
  21. import javax.persistence.Id;
  22. import javax.persistence.JoinColumn;
  23. import javax.persistence.OneToOne;
  24. import javax.persistence.Table;
  25. import javax.persistence.Transient;
  26. import java.util.Date;
  27. import java.util.List;
  28. import java.util.UUID;
  29.  
  30. /**
  31.  * @author Augusto Amarilla
  32.  * @since 6.5
  33.  */
  34.  
  35. @Entity
  36. @Table(name = "course_workflow_json_history")
  37. public class CourseWorkflowJsonHistory {
  38.  
  39.     public static final String JSONLATESTVERSION = "1.7";
  40.  
  41.     @Id
  42.     @Expose
  43.     @GeneratedValue(strategy = GenerationType.AUTO)
  44.     @Column(name = "course_workflow_json_history_id")
  45.     private Integer courseWorkflowJsonHistoryId;
  46.  
  47.     @Expose
  48.     @Column(name = "author_user_id")
  49.     private Integer authorUserId;
  50.  
  51.     @OneToOne
  52.     @Expose
  53.     @JoinColumn(name = "author_user_id", insertable = false, updatable = false)
  54.     private User authorUser;
  55.  
  56.     @Expose
  57.     @Column(name = "author_role_id")
  58.     private Integer authorRoleId;
  59.  
  60.     @OneToOne
  61.     @Expose
  62.     @JoinColumn(name = "author_role_id", insertable = false, updatable = false)
  63.     private Role authorRole;
  64.  
  65.     @Expose
  66.     @Column(name = "author_subrole_id")
  67.     private Integer authorSubroleId;
  68.  
  69.     @OneToOne
  70.     @Expose
  71.     @JoinColumn(name = "author_subrole_id", insertable = false, updatable = false)
  72.     private Subrole authorSubrole;
  73.  
  74.     @Expose
  75.     @Column(name = "json_object_id")
  76.     private String jsonObjectId;
  77.  
  78.     @Expose
  79.     @Column(name = "lst_mod_date")
  80.     private Date lastModificationDate;
  81.  
  82.     @Expose
  83.     @Column(name = "json_data")
  84.     @Convert(converter = JsonElementConverter.class)
  85.     private JsonElement jsonData;
  86.  
  87.     @Expose
  88.     @Column(name = "json_data",insertable = false,updatable = false)
  89.     @Convert(converter = CourseDtoConverter.class)
  90.     private CourseDTO courseDto;
  91.  
  92.     @Expose
  93.     @Column(name = "workflow_type")
  94.     private String workflowType;
  95.  
  96.     @Expose
  97.     @Column(name = "parent_json_object_id")
  98.     private String parentJsonObjectId;
  99.  
  100.     @Expose
  101.     @Column(name = "workflow_uuid")
  102.     private String workflowUUID;
  103.  
  104.     @Expose
  105.     @Column(name = "chair_report_id")
  106.     private Integer chairReportId;
  107.  
  108.     @Expose
  109.     @Column(name = "done")
  110.     private Boolean done = false;
  111.  
  112.     @Expose
  113.     @Column(name = "template_id")
  114.     private Integer templateId;
  115.  
  116.     @Expose
  117.     @Column(name = "committee_approval_date")
  118.     private Date committeeApprovalDate;
  119.  
  120.     @Expose
  121.     @Column(name = "org_id")
  122.     private Long orgId;
  123.  
  124.     @Expose
  125.     @Column(name = "code")
  126.     private String code;
  127.  
  128.     @Expose
  129.     @Column(name = "name")
  130.     private String name;
  131.  
  132.     @Column(name = "additional_system_field")
  133.     @Convert(converter = AdditionalSystemFieldValueConverter.class)
  134.     private AdditionalSystemFieldWrapper additionalSystemFieldWrapper;
  135.  
  136.  
  137.     @Transient
  138.     @Expose
  139.     private List<AdditionalSystemFieldDto> additionalSystemFieldList;
  140.  
  141.  
  142.     public CourseWorkflowJsonHistory() {
  143.         //Empty constructor
  144.         this.additionalSystemFieldList = additionalSystemFieldWrapper.getAdditionalSystemFieldDtoList();
  145.     }
  146.  
  147.     /**
  148.      * <p>Constructs an instance of {@link CourseWorkflowJsonHistory}</p>
  149.      * <p>The {@code jsonObjectId} is generated concatenating a new random UUID and the current date in milliseconds</p>
  150.      * <p>If the {@code lastModificationDate} is {@link null} the current date is used ({@code new Date()})</p>
  151.      *
  152.      * @param userId               User ID
  153.      * @param roleId               Role ID
  154.      * @param subroleId            Subrole ID
  155.      * @param lastModificationDate Last Modification Date
  156.      * @param jsonData             Course JsonData
  157.      * @param workflowType         Workflow Type
  158.      * @param parentJsonObjectId   Parent Json Object ID
  159.      * @param tempalteId           Workflow Template Id
  160.      * @param orgId                Id of the org entity for the base course
  161.      * @param code                 code of the base course
  162.      * @param name                 name of the base course
  163.      */
  164.     public CourseWorkflowJsonHistory(
  165.             Integer userId,
  166.             Integer roleId,
  167.             Integer subroleId,
  168.             Date lastModificationDate,
  169.             JsonElement jsonData,
  170.             String workflowType,
  171.             String parentJsonObjectId,
  172.             Integer tempalteId,
  173.             Long orgId,
  174.             String code,
  175.             String name
  176.     ) {
  177.         this.jsonObjectId = UUID.randomUUID().toString() + new Date().getTime();
  178.         this.authorUserId = userId;
  179.         this.authorRoleId = roleId;
  180.         if (subroleId != null && subroleId != 0) {
  181.             this.authorSubroleId = subroleId;
  182.         }
  183.         if (lastModificationDate == null) {
  184.             this.lastModificationDate = new Date();
  185.         } else {
  186.             this.lastModificationDate = lastModificationDate;
  187.         }
  188.         this.jsonData = jsonData;
  189.         this.workflowType = workflowType;
  190.         this.parentJsonObjectId = parentJsonObjectId;
  191.  
  192.         if (StringUtils.isBlank(parentJsonObjectId)) {
  193.             this.parentJsonObjectId = this.jsonObjectId;
  194.         } else {
  195.             this.parentJsonObjectId = parentJsonObjectId;
  196.         }
  197.         this.templateId = tempalteId;
  198.         this.orgId = orgId;
  199.         this.code = code;
  200.         this.name = name;
  201.     }
  202.  
  203.     public Integer getCourseWorkflowJsonHistoryId() {
  204.         return courseWorkflowJsonHistoryId;
  205.     }
  206.  
  207.     public void setCourseWorkflowJsonHistoryId(Integer courseWorkflowJsonHistoryId) {
  208.         this.courseWorkflowJsonHistoryId = courseWorkflowJsonHistoryId;
  209.     }
  210.  
  211.     public Integer getAuthorUserId() {
  212.         return authorUserId;
  213.     }
  214.  
  215.     public void setAuthorUserId(Integer authorUserId) {
  216.         this.authorUserId = authorUserId;
  217.     }
  218.  
  219.     public User getAuthorUser() {
  220.         return authorUser;
  221.     }
  222.  
  223.     public void setAuthorUser(User authorUser) {
  224.         this.authorUser = authorUser;
  225.     }
  226.  
  227.     public Integer getAuthorRoleId() {
  228.         return authorRoleId;
  229.     }
  230.  
  231.     public void setAuthorRoleId(Integer authorRoleId) {
  232.         this.authorRoleId = authorRoleId;
  233.     }
  234.  
  235.     public Role getAuthorRole() {
  236.         return authorRole;
  237.     }
  238.  
  239.     public void setAuthorRole(Role authorRole) {
  240.         this.authorRole = authorRole;
  241.     }
  242.  
  243.     public Integer getAuthorSubroleId() {
  244.         return authorSubroleId;
  245.     }
  246.  
  247.     public void setAuthorSubroleId(Integer authorSubroleId) {
  248.         this.authorSubroleId = authorSubroleId;
  249.     }
  250.  
  251.     public Subrole getAuthorSubrole() {
  252.         return authorSubrole;
  253.     }
  254.  
  255.     public void setAuthorSubrole(Subrole authorSubrole) {
  256.         this.authorSubrole = authorSubrole;
  257.     }
  258.  
  259.     public String getJsonObjectId() {
  260.         return jsonObjectId;
  261.     }
  262.  
  263.     public void setJsonObjectId(String jsonObjectId) {
  264.         this.jsonObjectId = jsonObjectId;
  265.     }
  266.  
  267.     public Date getLastModificationDate() {
  268.         return lastModificationDate;
  269.     }
  270.  
  271.     public void setLastModificationDate(Date lastModificationDate) {
  272.         this.lastModificationDate = lastModificationDate;
  273.     }
  274.  
  275.     /**
  276.      * Do not use this method. Use {@link CourseWorkflowJsonHistory#getJsonDataNormalized()}
  277.      * @return json data
  278.      * @deprecated Use {@link CourseWorkflowJsonHistory#getJsonDataNormalized()}
  279.      */
  280.     @Deprecated
  281.     public JsonElement getJsonData() {
  282.         return jsonData;
  283.     }
  284.  
  285.     public void setJsonData(JsonElement jsonData) {
  286.         this.jsonData = jsonData;
  287.     }
  288.  
  289.     public String getWorkflowType() {
  290.         return workflowType;
  291.     }
  292.  
  293.     public void setWorkflowType(String workflowType) {
  294.         this.workflowType = workflowType;
  295.     }
  296.  
  297.     public String getParentJsonObjectId() {return parentJsonObjectId; }
  298.  
  299.     public void setParentJsonObjectId(String parentJsonObjectId) { this.parentJsonObjectId = parentJsonObjectId; }
  300.  
  301.     public Boolean getDone() {
  302.         return done;
  303.     }
  304.  
  305.     public void setDone(Boolean done) {
  306.         this.done = done;
  307.     }
  308.  
  309.     public Integer getTemplateId() {
  310.         return templateId;
  311.     }
  312.  
  313.     public void setTemplateId(Integer templateId) {
  314.         this.templateId = templateId;
  315.     }
  316.  
  317.     /**
  318.      * @return An UUID object from the string field stored in database,
  319.      * if no string stored null is returned
  320.      */
  321.     public UUID getWorkflowUUID() {
  322.         if (StringUtils.isNotBlank(workflowUUID)) {
  323.             return UUID.fromString(this.workflowUUID);
  324.         } else {
  325.             return null;
  326.         }
  327.     }
  328.  
  329.     /**
  330.      * @param workflowUUID is an UUID object that if not null will be
  331.      *                     represented as string and store that representation in the
  332.      *                     Bean property
  333.      */
  334.     public void setWorkflowUUID(UUID workflowUUID) {
  335.         if (workflowUUID != null) {
  336.             this.workflowUUID = workflowUUID.toString();
  337.         } else {
  338.             this.workflowUUID = null;
  339.         }
  340.     }
  341.  
  342.     public JsonElement getJsonDataNormalized() {
  343.         if (jsonData == null) {
  344.             return null;
  345.         }
  346.         JsonObject data = jsonData.getAsJsonObject();
  347.         if (data.has("version") && JSONLATESTVERSION.equals(data.get("version").getAsString())) {
  348.             return jsonData;
  349.         } else {
  350.             CourseWorkflowJsonUpdateService updateService = new CourseWorkflowJsonUpdateService();
  351.             return updateService.getAsLatest(data);
  352.         }
  353.     }
  354.  
  355.     // Adding no sonar since it's auto-generated code
  356.     @Override
  357.     public boolean equals(Object o) {//NOSONAR
  358.         if (this == o) {
  359.             return true;
  360.         }
  361.         if (o == null || getClass() != o.getClass()) {
  362.             return false;
  363.         }
  364.  
  365.         CourseWorkflowJsonHistory that = (CourseWorkflowJsonHistory) o;
  366.  
  367.         if (!courseWorkflowJsonHistoryId.equals(that.courseWorkflowJsonHistoryId)) {
  368.             return false;
  369.         }
  370.         if (!authorUserId.equals(that.authorUserId)) {
  371.             return false;
  372.         }
  373.         if (authorUser != null ? !authorUser.equals(that.authorUser) : (that.authorUser != null)) {
  374.             return false;
  375.         }
  376.         if (!authorRoleId.equals(that.authorRoleId)) {
  377.             return false;
  378.         }
  379.         if (authorRole != null ? !authorRole.equals(that.authorRole) : (that.authorRole != null)) {
  380.             return false;
  381.         }
  382.         if (authorSubroleId != null ? !authorSubroleId.equals(that.authorSubroleId) : (that.authorSubroleId != null)) {
  383.             return false;
  384.         }
  385.         if (authorSubrole != null ? !authorSubrole.equals(that.authorSubrole) : (that.authorSubrole != null)) {
  386.             return false;
  387.         }
  388.         if (!jsonObjectId.equals(that.jsonObjectId)) {
  389.             return false;
  390.         }
  391.         if (!lastModificationDate.equals(that.lastModificationDate)) {
  392.             return false;
  393.         }
  394.         if (!jsonData.equals(that.jsonData)) {
  395.             return false;
  396.         }
  397.  
  398.         return true;
  399.     }
  400.  
  401.     @Override
  402.     public int hashCode() {
  403.         int result = courseWorkflowJsonHistoryId.hashCode();
  404.         result = 31 * result + authorUserId.hashCode();
  405.         result = 31 * result + (authorUser != null ? authorUser.hashCode() : 0);
  406.         result = 31 * result + authorRoleId.hashCode();
  407.         result = 31 * result + (authorRole != null ? authorRole.hashCode() : 0);
  408.         result = 31 * result + (authorSubroleId != null ? authorSubroleId.hashCode() : 0);
  409.         result = 31 * result + (authorSubrole != null ? authorSubrole.hashCode() : 0);
  410.         result = 31 * result + jsonObjectId.hashCode();
  411.         result = 31 * result + lastModificationDate.hashCode();
  412.         result = 31 * result + jsonData.hashCode();
  413.         return result;
  414.     }
  415.  
  416.     /**
  417.      * Performs a clone of the object returning a new instance of it
  418.      *
  419.      * @return Cloned CourseWorkflowJsonHistory without Id
  420.      */
  421.     public CourseWorkflowJsonHistory copyNoId() {
  422.         CourseWorkflowJsonHistory newHistory = new CourseWorkflowJsonHistory();
  423.         Gson gson = new Gson();
  424.         newHistory.setJsonData(gson.fromJson(gson.toJson(jsonData, JsonElement.class), JsonElement.class));
  425.         newHistory.setLastModificationDate(lastModificationDate);
  426.         newHistory.setAuthorRole(authorRole);
  427.         newHistory.setAuthorRoleId(authorRoleId);
  428.         newHistory.setAuthorSubrole(authorSubrole);
  429.         newHistory.setAuthorSubroleId(authorSubroleId);
  430.         newHistory.setJsonObjectId(jsonObjectId);
  431.         newHistory.setParentJsonObjectId(parentJsonObjectId);
  432.         newHistory.setWorkflowType(workflowType);
  433.         newHistory.setAuthorUser(authorUser);
  434.         newHistory.setAuthorUserId(authorUserId);
  435.         newHistory.setChairReportId(chairReportId);
  436.         newHistory.setTemplateId(templateId);
  437.         newHistory.setDone(done);
  438.         newHistory.setName(name);
  439.         newHistory.setCode(code);
  440.         newHistory.setOrgId(orgId);
  441.         newHistory.setCommitteeApprovalDate(committeeApprovalDate);
  442.         if (workflowUUID != null) {
  443.             newHistory.setWorkflowUUID(UUID.fromString(workflowUUID));
  444.         }else {
  445.             newHistory.setWorkflowUUID(UUID.randomUUID());
  446.         }
  447.  
  448.  
  449.         return newHistory;
  450.     }
  451.  
  452.     public Integer getChairReportId() {
  453.         return chairReportId;
  454.     }
  455.  
  456.     public void setChairReportId(Integer chairReportId) {
  457.         this.chairReportId = chairReportId;
  458.     }
  459.  
  460.     public Date getCommitteeApprovalDate() {
  461.         return committeeApprovalDate;
  462.     }
  463.  
  464.     public void setCommitteeApprovalDate(Date committeeApprovalDate) {
  465.         this.committeeApprovalDate = committeeApprovalDate;
  466.     }
  467.  
  468.     public Long getOrgId() {
  469.         return orgId;
  470.     }
  471.  
  472.     public void setOrgId(Long orgId) {
  473.         this.orgId = orgId;
  474.     }
  475.  
  476.     public String getCode() {
  477.         return code;
  478.     }
  479.  
  480.     public void setCode(String code) {
  481.         this.code = code;
  482.     }
  483.  
  484.     public String getName() {
  485.         return name;
  486.     }
  487.  
  488.     public void setName(String name) {
  489.         this.name = name;
  490.     }
  491.  
  492.     public CourseDTO getCourseDto() {
  493.         return courseDto;
  494.     }
  495.  
  496.     public void setCourseDto(CourseDTO courseDto) {
  497.         this.courseDto = courseDto;
  498.     }
  499.  
  500.     public List<AdditionalSystemFieldDto> getAdditionalSystemFieldList() {
  501.         return additionalSystemFieldList;
  502.     }
  503.  
  504.     public void setAdditionalSystemFieldList(List<AdditionalSystemFieldDto> additionalSystemFieldDtoList) {
  505.         this.additionalSystemFieldWrapper = new AdditionalSystemFieldWrapper();
  506.         this.additionalSystemFieldWrapper.setAdditionalSystemFieldDtoList(additionalSystemFieldDtoList);
  507.     }
  508.  
  509.  
  510. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement