Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
297 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
(Please put at the bottom of the list under 🌐 API) | ||
|
||
### Experimental Make Data Count processingState API | ||
|
||
An experimental Make Data Count processingState API has been added. For now it has been documented in the developer guide: https://guides.dataverse.org/en/6.2/developers/make-data-count.html#processing-archived-logs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/main/java/edu/harvard/iq/dataverse/makedatacount/MakeDataCountProcessState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package edu.harvard.iq.dataverse.makedatacount; | ||
|
||
import jakarta.persistence.*; | ||
|
||
import java.io.Serializable; | ||
import java.sql.Timestamp; | ||
import java.time.Instant; | ||
import java.util.Arrays; | ||
|
||
@Entity | ||
@Table(indexes = {@Index(columnList="yearMonth")}) | ||
public class MakeDataCountProcessState implements Serializable { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(nullable = false) | ||
private Long id; | ||
|
||
public enum MDCProcessState { | ||
NEW("new"), DONE("done"), SKIP("skip"), PROCESSING("processing"), FAILED("failed"); | ||
private final String text; | ||
private MDCProcessState(final String text) { | ||
this.text = text; | ||
} | ||
public static MDCProcessState fromString(String text) { | ||
if (text != null) { | ||
for (MDCProcessState state : MDCProcessState.values()) { | ||
if (text.equals(state.text)) { | ||
return state; | ||
} | ||
} | ||
} | ||
throw new IllegalArgumentException("State must be one of these values: " + Arrays.asList(MDCProcessState.values()) + "."); | ||
} | ||
@Override | ||
public String toString() { | ||
return text; | ||
} | ||
} | ||
@Column(nullable = false) | ||
private String yearMonth; | ||
@Column(nullable = false) | ||
private MDCProcessState state; | ||
@Column(nullable = true) | ||
private Timestamp stateChangeTimestamp; | ||
|
||
public MakeDataCountProcessState() { } | ||
public MakeDataCountProcessState (String yearMonth, String state) { | ||
this.setYearMonth(yearMonth); | ||
this.setState(state); | ||
} | ||
|
||
public void setYearMonth(String yearMonth) throws IllegalArgumentException { | ||
// Todo: add constraint | ||
if (yearMonth == null || (!yearMonth.matches("\\d{4}-\\d{2}") && !yearMonth.matches("\\d{4}-\\d{2}-\\d{2}"))) { | ||
throw new IllegalArgumentException("YEAR-MONTH date format must be either yyyy-mm or yyyy-mm-dd"); | ||
} | ||
this.yearMonth = yearMonth; | ||
} | ||
public String getYearMonth() { | ||
return this.yearMonth; | ||
} | ||
public void setState(MDCProcessState state) { | ||
this.state = state; | ||
this.stateChangeTimestamp = Timestamp.from(Instant.now()); | ||
} | ||
public void setState(String state) throws IllegalArgumentException { | ||
setState(MDCProcessState.fromString(state)); | ||
} | ||
public MDCProcessState getState() { | ||
return this.state; | ||
} | ||
public Timestamp getStateChangeTime() { | ||
return stateChangeTimestamp; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...ain/java/edu/harvard/iq/dataverse/makedatacount/MakeDataCountProcessStateServiceBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package edu.harvard.iq.dataverse.makedatacount; | ||
|
||
import jakarta.ejb.EJBException; | ||
import jakarta.ejb.Stateless; | ||
import jakarta.inject.Named; | ||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.PersistenceContext; | ||
import jakarta.persistence.Query; | ||
|
||
import java.util.List; | ||
|
||
@Named | ||
@Stateless | ||
public class MakeDataCountProcessStateServiceBean { | ||
|
||
@PersistenceContext(unitName = "VDCNet-ejbPU") | ||
protected EntityManager em; | ||
|
||
public MakeDataCountProcessState getMakeDataCountProcessState(String yearMonth) { | ||
validateYearMonth(yearMonth); | ||
MakeDataCountProcessState mdcps = null; | ||
String queryStr = "SELECT d FROM MakeDataCountProcessState d WHERE d.yearMonth = '" + yearMonth + "' "; | ||
Query query = em.createQuery(queryStr); | ||
List resultList = query.getResultList(); | ||
if (resultList.size() > 1) { | ||
throw new EJBException("More than one MakeDataCount Process State record found for YearMonth " + yearMonth + "."); | ||
} | ||
if (resultList.size() == 1) { | ||
mdcps = (MakeDataCountProcessState) resultList.get(0); | ||
} | ||
return mdcps; | ||
} | ||
|
||
public MakeDataCountProcessState setMakeDataCountProcessState(String yearMonth, String state) { | ||
MakeDataCountProcessState mdcps = getMakeDataCountProcessState(yearMonth); | ||
if (mdcps == null) { | ||
mdcps = new MakeDataCountProcessState(yearMonth, state); | ||
} else { | ||
mdcps.setState(state); | ||
} | ||
return em.merge(mdcps); | ||
} | ||
|
||
public boolean deleteMakeDataCountProcessState(String yearMonth) { | ||
MakeDataCountProcessState mdcps = getMakeDataCountProcessState(yearMonth); | ||
if (mdcps == null) { | ||
return false; | ||
} else { | ||
em.remove(mdcps); | ||
em.flush(); | ||
return true; | ||
} | ||
} | ||
|
||
private void validateYearMonth(String yearMonth) { | ||
// Check yearMonth format. either yyyy-mm or yyyy-mm-dd | ||
if (yearMonth == null || (!yearMonth.matches("\\d{4}-\\d{2}") && !yearMonth.matches("\\d{4}-\\d{2}-\\d{2}"))) { | ||
throw new IllegalArgumentException("YEAR-MONTH date format must be either yyyy-mm or yyyy-mm-dd"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters