-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v1 Scheduled Jobs / Third Party Sync Migration #171
base: master
Are you sure you want to change the base?
Changes from 46 commits
2afc27f
6712e00
b99c788
815e30d
09b28bf
97b0dfb
542c530
596970b
08812c4
4233988
023b65d
0c27798
44b00ec
a8b4ad4
41a6899
581169f
e1cc0d1
9c3b156
e1b586b
11d0841
1753761
9988f38
38ed481
e925acd
cb6c841
d551add
c91f2f9
026b63e
23d5112
73739ac
01684cd
685f707
abd3493
a7f7b1e
09c5460
217dd67
40f9568
26d3241
f43cf29
6e4f247
88aa990
97eaa0c
9e0d560
a9a1336
88fa2ea
069b660
78167c4
fd4ba88
91912ac
59ec8b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
package com.box.l10n.mojito.entity; | ||
|
||
import com.box.l10n.mojito.json.ObjectMapper; | ||
import com.box.l10n.mojito.service.scheduledjob.ScheduledJobProperties; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.ForeignKey; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.PostLoad; | ||
import jakarta.persistence.Table; | ||
import jakarta.persistence.Transient; | ||
import java.time.ZonedDateTime; | ||
import org.hibernate.envers.Audited; | ||
|
||
@Audited | ||
@Entity | ||
@Table(name = "scheduled_job") | ||
public class ScheduledJob { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(name = "uuid") | ||
private String uuid; | ||
|
||
@ManyToOne | ||
@JoinColumn( | ||
name = "repository_id", | ||
foreignKey = @ForeignKey(name = "FK__SCHEDULED_JOB__IMPORT_REPOSITORY__ID")) | ||
private Repository repository; | ||
garionpin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@ManyToOne | ||
@JoinColumn(name = "job_type", foreignKey = @ForeignKey(name = "FK__JOB_TYPE__JOB_TYPE_ID")) | ||
private ScheduledJobType jobType; | ||
|
||
@Column(name = "cron") | ||
private String cron; | ||
|
||
@Transient private ScheduledJobProperties properties; | ||
garionpin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@Column(name = "properties") | ||
private String propertiesString; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "job_status", foreignKey = @ForeignKey(name = "FK__JOB_STATUS__JOB_STATUS_ID")) | ||
private ScheduledJobStatus jobStatus; | ||
|
||
@Column(name = "start_date") | ||
private ZonedDateTime startDate; | ||
|
||
@Column(name = "end_date") | ||
private ZonedDateTime endDate; | ||
|
||
@Column(name = "enabled") | ||
private Boolean enabled = true; | ||
|
||
@PostLoad | ||
public void deserializeProperties() { | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
try { | ||
this.properties = | ||
objectMapper.readValue(propertiesString, jobType.getEnum().getPropertiesClass()); | ||
} catch (Exception e) { | ||
throw new RuntimeException( | ||
"Failed to deserialize properties '" | ||
+ propertiesString | ||
+ "' for class: " | ||
+ jobType.getEnum().getPropertiesClass().getName(), | ||
e); | ||
} | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getUuid() { | ||
return uuid; | ||
} | ||
|
||
public void setUuid(String uuid) { | ||
this.uuid = uuid; | ||
} | ||
|
||
public Repository getRepository() { | ||
return repository; | ||
} | ||
|
||
public void setRepository(Repository repository) { | ||
this.repository = repository; | ||
} | ||
|
||
public ScheduledJobType getJobType() { | ||
return jobType; | ||
} | ||
|
||
public void setJobType(ScheduledJobType jobType) { | ||
this.jobType = jobType; | ||
} | ||
|
||
public String getCron() { | ||
return cron; | ||
} | ||
|
||
public void setCron(String cron) { | ||
this.cron = cron; | ||
} | ||
|
||
public ScheduledJobProperties getProperties() { | ||
return properties; | ||
} | ||
|
||
public void setProperties(ScheduledJobProperties properties) { | ||
this.properties = properties; | ||
|
||
ObjectMapper objectMapper = new ObjectMapper(); | ||
try { | ||
this.propertiesString = objectMapper.writeValueAsString(this.properties); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Failed to serialize properties", e); | ||
} | ||
} | ||
|
||
public String getPropertiesString() { | ||
return propertiesString; | ||
} | ||
|
||
public void setPropertiesString(String properties) { | ||
this.propertiesString = properties; | ||
} | ||
|
||
public ScheduledJobStatus getJobStatus() { | ||
return jobStatus; | ||
} | ||
|
||
public void setJobStatus(ScheduledJobStatus jobStatus) { | ||
this.jobStatus = jobStatus; | ||
} | ||
|
||
public ZonedDateTime getStartDate() { | ||
return startDate; | ||
} | ||
|
||
public void setStartDate(ZonedDateTime startDate) { | ||
this.startDate = startDate; | ||
} | ||
|
||
public ZonedDateTime getEndDate() { | ||
return endDate; | ||
} | ||
|
||
public void setEndDate(ZonedDateTime endDate) { | ||
this.endDate = endDate; | ||
} | ||
|
||
public Boolean getEnabled() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be named |
||
return enabled; | ||
} | ||
|
||
public void setEnabled(Boolean enabled) { | ||
this.enabled = enabled; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.box.l10n.mojito.entity; | ||
|
||
import static org.hibernate.envers.RelationTargetAuditMode.NOT_AUDITED; | ||
|
||
import com.box.l10n.mojito.rest.View; | ||
import com.fasterxml.jackson.annotation.JsonView; | ||
import jakarta.persistence.Basic; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import org.hibernate.envers.Audited; | ||
|
||
@Entity | ||
@Table(name = "scheduled_job_status_type") | ||
@Audited(targetAuditMode = NOT_AUDITED) | ||
public class ScheduledJobStatus extends BaseEntity { | ||
@Id private Long id; | ||
|
||
@Basic(optional = false) | ||
@Column(name = "name") | ||
@Enumerated(EnumType.STRING) | ||
@JsonView(View.Repository.class) | ||
private com.box.l10n.mojito.service.scheduledjob.ScheduledJobStatus jobStatus; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use an import here? This looks funky to me There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No we can't, the name of the imported class matches the name of the current class, the definition needs to be this specific. |
||
|
||
public com.box.l10n.mojito.service.scheduledjob.ScheduledJobStatus getEnum() { | ||
return jobStatus; | ||
} | ||
|
||
public void setJobStatus(com.box.l10n.mojito.service.scheduledjob.ScheduledJobStatus jobStatus) { | ||
this.jobStatus = jobStatus; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.box.l10n.mojito.entity; | ||
|
||
import static org.hibernate.envers.RelationTargetAuditMode.NOT_AUDITED; | ||
|
||
import com.box.l10n.mojito.rest.View; | ||
import com.fasterxml.jackson.annotation.JsonView; | ||
import jakarta.persistence.Basic; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import org.hibernate.envers.Audited; | ||
|
||
@Entity | ||
@Table(name = "scheduled_job_type") | ||
@Audited(targetAuditMode = NOT_AUDITED) | ||
public class ScheduledJobType extends BaseEntity { | ||
@Id private Long id; | ||
|
||
@Basic(optional = false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hold on. Why is this needed? The column is not not nullable, so should the config not reflect that. This Basic property to my understanding enforces that the property is not null locally but not at a db level (I might be wrong) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have updated the other columns that are not nullable to have this, I noticed it was on other entity objects so I decided to use it. It looks like you can generate SQL schemas off of entity mappings, not that we would need to use this but best practice to have annotations like this! |
||
@Column(name = "name") | ||
@Enumerated(EnumType.STRING) | ||
@JsonView(View.Repository.class) | ||
private com.box.l10n.mojito.service.scheduledjob.ScheduledJobType jobType; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar comment as before There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check previous comment. |
||
|
||
@Override | ||
public Long getId() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public com.box.l10n.mojito.service.scheduledjob.ScheduledJobType getEnum() { | ||
return jobType; | ||
} | ||
|
||
public void setEnum(com.box.l10n.mojito.service.scheduledjob.ScheduledJobType jobType) { | ||
this.jobType = jobType; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we extend
BaseEntity
here, which will then provide theid
field handling in the parent class? Might have missed a previous conversation about this