Skip to content

Commit

Permalink
111323: Expose creationTime sort option on Process endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
nona-luypaert committed Jan 24, 2024
1 parent 5a43e6b commit bf5ea2d
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public ProcessBuilder withCreationTime(Date creationTime) {

public ProcessBuilder withStartAndEndTime(String startTime, String endTime) throws ParseException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
process.setStartTime(simpleDateFormat.parse(startTime));
process.setFinishedTime(simpleDateFormat.parse(endTime));
process.setStartTime(startTime == null ? null : simpleDateFormat.parse(startTime));
process.setFinishedTime(endTime == null ? null : simpleDateFormat.parse(endTime));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public ProcessRest convert(Process process, Projection projection) {
processRest.setProcessStatus(process.getProcessStatus());
processRest.setStartTime(process.getStartTime());
processRest.setEndTime(process.getFinishedTime());
processRest.setCreationTime(process.getCreationTime());
processRest.setParameterRestList(processService.getParameters(process).stream()
.map(x -> (ParameterValueRest) converter.toRest(x, projection)).collect(Collectors.toList()));
return processRest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public String getType() {
private Integer processId;
private Date startTime;
private Date endTime;
private Date creationTime;
private ProcessStatus processStatus;
@JsonProperty(value = "parameters")
private List<ParameterValueRest> parameterRestList;
Expand Down Expand Up @@ -104,6 +105,14 @@ public void setStartTime(Date startTime) {
this.startTime = startTime;
}

public Date getCreationTime() {
return creationTime;
}

public void setCreationTime(Date creationTime) {
this.creationTime = creationTime;
}

public String getScriptName() {
return scriptName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ private void handleSearchSort(Pageable pageable, ProcessQueryParameterContainer
} else if (StringUtils.equalsIgnoreCase(order.getProperty(), "endTime")) {
processQueryParameterContainer.setSortProperty(Process_.FINISHED_TIME);
processQueryParameterContainer.setSortOrder(order.getDirection().name());
} else if (StringUtils.equalsIgnoreCase(order.getProperty(), "creationTime")) {
processQueryParameterContainer.setSortProperty(Process_.CREATION_TIME);
processQueryParameterContainer.setSortOrder(order.getDirection().name());
} else {
throw new DSpaceBadRequestException("The given sort option was invalid: " + order.getProperty());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.io.InputStream;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
Expand Down Expand Up @@ -689,6 +690,78 @@ public void searchProcessTestByUserSortedOnStartTimeDesc() throws Exception {
PageMatcher.pageEntryWithTotalPagesAndElements(0, 20, 1, 3))));
}

@Test
public void searchProcessTestByUserSortedOnCreationTimeAsc() throws Exception {
SimpleDateFormat date = new SimpleDateFormat("dd/MM/yyyy");
Process newProcess1 = ProcessBuilder.createProcess(context, eperson, "mock-script", parameters)
// not realistic to have creationTime after startTime,
// but proves startTime is ignored on sort
.withCreationTime(date.parse("01/01/2000"))
.withStartAndEndTime("01/01/1990", "01/01/1995").build();
Process newProcess2 = ProcessBuilder.createProcess(context, eperson, "mock-script", parameters)
.withCreationTime(date.parse("01/01/2005"))
.withStartAndEndTime(null, null).build();
Process newProcess3 = ProcessBuilder.createProcess(context, eperson, "mock-script", parameters)
.withCreationTime(date.parse("01/01/2010"))
.withStartAndEndTime("01/01/2015", "01/01/2020").build();

String token = getAuthToken(admin.getEmail(), password);

getClient(token).perform(get("/api/system/processes/search/byProperty")
.param("userId", eperson.getID().toString())
.param("sort", "creationTime,asc"))
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.processes", contains(
ProcessMatcher.matchProcess(newProcess1.getName(),
String.valueOf(eperson.getID().toString()),
newProcess1.getID(), parameters, ProcessStatus.SCHEDULED),
ProcessMatcher.matchProcess(newProcess2.getName(),
String.valueOf(eperson.getID().toString()),
newProcess2.getID(), parameters, ProcessStatus.SCHEDULED),
ProcessMatcher.matchProcess(newProcess3.getName(),
String.valueOf(eperson.getID().toString()),
newProcess3.getID(), parameters, ProcessStatus.SCHEDULED)
)))
.andExpect(jsonPath("$.page", is(
PageMatcher.pageEntryWithTotalPagesAndElements(0, 20, 1, 3))));
}

@Test
public void searchProcessTestByUserSortedOnCreationTimeDesc() throws Exception {
SimpleDateFormat date = new SimpleDateFormat("dd/MM/yyyy");
Process newProcess1 = ProcessBuilder.createProcess(context, eperson, "mock-script", parameters)
// not realistic to have creationTime after startTime,
// but proves startTime is ignored on sort
.withCreationTime(date.parse("01/01/2000"))
.withStartAndEndTime("01/01/1990", "01/01/1995").build();
Process newProcess2 = ProcessBuilder.createProcess(context, eperson, "mock-script", parameters)
.withCreationTime(date.parse("01/01/2005"))
.withStartAndEndTime(null, null).build();
Process newProcess3 = ProcessBuilder.createProcess(context, eperson, "mock-script", parameters)
.withCreationTime(date.parse("01/01/2010"))
.withStartAndEndTime("01/01/2015", "01/01/2020").build();

String token = getAuthToken(admin.getEmail(), password);

getClient(token).perform(get("/api/system/processes/search/byProperty")
.param("userId", eperson.getID().toString())
.param("sort", "creationTime,desc"))
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.processes", contains(
ProcessMatcher.matchProcess(newProcess3.getName(),
String.valueOf(eperson.getID().toString()),
newProcess3.getID(), parameters, ProcessStatus.SCHEDULED),
ProcessMatcher.matchProcess(newProcess2.getName(),
String.valueOf(eperson.getID().toString()),
newProcess2.getID(), parameters, ProcessStatus.SCHEDULED),
ProcessMatcher.matchProcess(newProcess1.getName(),
String.valueOf(eperson.getID().toString()),
newProcess1.getID(), parameters, ProcessStatus.SCHEDULED)
)))
.andExpect(jsonPath("$.page", is(
PageMatcher.pageEntryWithTotalPagesAndElements(0, 20, 1, 3))));
}

@Test
public void searchProcessTestByUserSortedOnEndTimeAsc() throws Exception {
Process newProcess1 = ProcessBuilder.createProcess(context, eperson, "mock-script", parameters)
Expand Down Expand Up @@ -797,7 +870,7 @@ public void searchProcessTestByUserSortedOnDefault() throws Exception {
}

@Test
public void searchProcessTestByUserSortedOnNonExistingIsSortedAsDefault() throws Exception {
public void searchProcessTestByUserSortedOnNonExistingBadRequest() throws Exception {
Process newProcess1 = ProcessBuilder.createProcess(context, eperson, "mock-script", parameters)
.withStartAndEndTime("10/01/1990", "20/01/1990").build();
Process newProcess2 = ProcessBuilder.createProcess(context, eperson, "mock-script", parameters)
Expand Down

0 comments on commit bf5ea2d

Please sign in to comment.