Skip to content

Commit

Permalink
Merged in task/dspace-cris-2023_02_x/DSC-1883-AddStartDateTime (pull …
Browse files Browse the repository at this point in the history
…request DSpace#2844)

DSC-1883: Add the startDateTime metadata to the dspace schema

Approved-by: Daniele Ninfo
  • Loading branch information
Micheleboychuk authored and danieleninfo committed Nov 18, 2024
2 parents 82ab1d7 + aa39d8c commit 6636fe9
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@

import java.io.IOException;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.TimeZone;
import java.util.UUID;
import javax.mail.MessagingException;
import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -249,14 +253,22 @@ public XmlWorkflowItem start(Context context, WorkspaceItem wsi)
itemService.getIdentifiers(context, wfi.getItem())));

}

addStartDateMetadata(context, myitem);
context.restoreAuthSystemState();
return wfi;
} catch (WorkflowConfigurationException e) {
throw new WorkflowException(e);
}
}

private void addStartDateMetadata(Context context, Item myitem) throws SQLException, AuthorizeException {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
String date = dateFormat.format(new Date());
itemService.addMetadata(context, myitem,"dspace", "workflow","startDateTime", null, date);
itemService.update(context, myitem);
}

//TODO: this is currently not used in our notifications. Look at the code used by the original WorkflowManager

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public void testWorkbookBuildingFromItemDtos() throws Exception {

Item firstItem = getItemFromMessage(handler.getInfoMessages().get(7));
assertThat(firstItem, notNullValue());
assertThat(firstItem.getMetadata(), hasSize(18));
assertThat(firstItem.getMetadata(), hasSize(19));
assertThat(firstItem.getMetadata(), hasItems(
with("dc.title", "Test Publication"),
with("dc.date.issued", "2020/02/15"),
Expand All @@ -229,7 +229,7 @@ public void testWorkbookBuildingFromItemDtos() throws Exception {

Item secondItem = getItemFromMessage(handler.getInfoMessages().get(10));
assertThat(secondItem, notNullValue());
assertThat(secondItem.getMetadata(), hasSize(22));
assertThat(secondItem.getMetadata(), hasSize(23));
assertThat(secondItem.getMetadata(), hasItems(
with("dc.title", "Second Publication"),
with("dc.date.issued", "2022/02/15"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ public void testRunHarvestWithSubmissionNotEnabled() throws Exception {

Item item = workflowItems.get(0).getItem();
assertThat(item.isArchived(), equalTo(false));
assertThat(item.getMetadata(), hasSize(7));
assertThat(item.getMetadata(), hasSize(8));
assertThat(harvestedItemService.find(context, item), notNullValue());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ public void startWorkflow() throws IOException {
assertEquals("Is the workflow item the right one?", item, xwil.get(0).getItem());

List<MetadataValue> metadata = item.getMetadata();
assertEquals("Four metadata found", 4, metadata.size());
assertEquals("Four metadata found", 5, metadata.size());
for (MetadataValue m : metadata) {
if ("contributor".equals(m.getElement())) {
assertEquals("The dc.contibutor.autor is the right one!", m.getValue(), "Francesco Cadili");
Expand All @@ -966,6 +966,8 @@ public void startWorkflow() throws IOException {
m.getValue().indexOf("workflow start=Step: reviewstep - action:claimaction") > 0);
} else if ("sourceId".equals(m.getElement())) {
assertNotNull("The source id is the right one! ", "TEST::1");
} else if ("workflow".equals(m.getElement()) && "startDateTime".equals(m.getQualifier())) {
assertNotNull("The dspace.workflow.startDateTime is not null! ", m.getValue());
} else {
assertTrue("Metadata is not valid.", m == null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
Expand Down Expand Up @@ -2886,4 +2887,30 @@ public void patchAddMetadataToInlineGroupTypeMetadataShouldCompletedWithoutError
is("12312")));;
}

@Test
public void checkStartDateTimeTest() throws Exception {
context.turnOffAuthorisationSystem();
context.setCurrentUser(admin);
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, parentCommunity)
.withName("Collection 1")
.withWorkflowGroup(1, admin).build();

XmlWorkflowItem workflowItem = WorkflowItemBuilder.createWorkflowItem(context, col1)
.withTitle("Workflow Item 1")
.withIssueDate("2024-10-07")
.build();

Item item = workflowItem.getItem();
context.restoreAuthSystemState();

String adminToken = getAuthToken(admin.getEmail(), password);
getClient(adminToken).perform(get("/api/core/items/" + item.getID()))
.andExpect(status().isOk())
.andExpect(jsonPath("$.inArchive", is(false)))
.andExpect(jsonPath("$.metadata['dspace.workflow.startDateTime'][0].value", notNullValue()));
}

}
7 changes: 7 additions & 0 deletions dspace/config/registries/dspace-types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,11 @@
<scope_note/>
</dc-type>

<dc-type>
<schema>dspace</schema>
<element>workflow</element>
<qualifier>startDateTime</qualifier>
<scope_note/>
</dc-type>

</dspace-dc-types>

0 comments on commit 6636fe9

Please sign in to comment.