forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ufal/downloading-restricted-bitstreams-not-working-properly (#457) * The admin could download restricted bitstreams. * The user cannot download bitstream if he/she is not signed in. * Cannot obtain context with user. * The user is already fetched from the context. * Added docs. * Do not use endpoint for downloading the single file because it already exists - remove it. * Fixed AuthorizationRestControllerIT tests. * ufal/be-cannot-download-and-preview-files-after-migration (#454) * Find bitstream format using mimetype not ID. * Updated tests according to fix. * ufal/update-canonical-prefix-to-hdl (#460) * Updated `handle.canonical.prefix` to hdl handle. * Integration test cannot have changed handle.canonical.prefix. * ufal/be-user-registration-missing (#463) * The user registration is added when the eperson is created by the ui. * try using newer checkout, same as upstream, since error is with git --------- Co-authored-by: MajoBerger <[email protected]> * ufal/be-license-download-statistics (#462) * Add logging of downloading restricted bitstreams. * Log downloading of every bitstream not only restricted ones. * Added docs * Refactored logging. * ufal/be-shibboleth-headers-encoding (#464) * givenname and last name values are converted to UTF-8 encoding * Delete eperson in tests * using our dspace-dependencies because of #466 * ufal/be-fix-email-parameters Fixed emails sending - added arguments and cfg properties that are sent in the email. (#470) * ufal/be-provenance-subbmitter-missing (#469) * DSpace#8585 Add submitter information to provenance metadata * Cherry picked fix from vanilla and added test to check if the Item provenance metadata is added --------- Co-authored-by: Adán Román Ruiz <[email protected]> * ufal/be-get-user-ip-address (#468) * Created endpoint for fetching IP address with tests. * Made the code more understable * ufal/publisher-ok-fix (#473) * fixes ufal#1096 (#471) * Added publisher filter in the integration test check --------- Co-authored-by: Ondřej Košarko <[email protected]> --------- Co-authored-by: MajoBerger <[email protected]> Co-authored-by: MajoBerger <[email protected]> Co-authored-by: Adán Román Ruiz <[email protected]> Co-authored-by: Ondřej Košarko <[email protected]>
- Loading branch information
1 parent
5968c7b
commit 3d88a75
Showing
12 changed files
with
271 additions
and
32 deletions.
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
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
56 changes: 56 additions & 0 deletions
56
dspace-server-webapp/src/main/java/org/dspace/app/rest/ClarinUserInfoController.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,56 @@ | ||
/** | ||
* The contents of this file are subject to the license and copyright | ||
* detailed in the LICENSE and NOTICE files at the root of the source | ||
* tree and available online at | ||
* | ||
* http://www.dspace.org/license/ | ||
*/ | ||
package org.dspace.app.rest; | ||
|
||
import java.io.IOException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* This class is a REST controller that returns information about the client user. | ||
* E.g. the client's IP address. | ||
* | ||
* @author Milan Majchrak (milan.majchrak at dataquest.sk) | ||
*/ | ||
@RequestMapping(value = "/api/userinfo") | ||
@RestController | ||
public class ClarinUserInfoController { | ||
|
||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
/** | ||
* This method returns the client's IP address. | ||
* @param request The HttpServletRequest object. | ||
* @return The client's IP address. | ||
*/ | ||
@RequestMapping(method = RequestMethod.GET, path = "/ipaddress") | ||
public ResponseEntity<Object> getUserIPAddress(HttpServletRequest request, HttpServletResponse response) | ||
throws IOException { | ||
// Get client's IP address | ||
String ipAddress = request.getRemoteAddr(); | ||
if (StringUtils.isBlank(ipAddress)) { | ||
String errorMessage = "Cannot get user's IP address"; | ||
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, errorMessage); | ||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorMessage); | ||
} | ||
|
||
// Create JSON object using Jackson's ObjectNode | ||
ObjectNode jsonObject = objectMapper.createObjectNode(); | ||
jsonObject.put("ipAddress", ipAddress); | ||
|
||
return ResponseEntity.ok().body(jsonObject); | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinUserInfoControllerIT.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,34 @@ | ||
/** | ||
* The contents of this file are subject to the license and copyright | ||
* detailed in the LICENSE and NOTICE files at the root of the source | ||
* tree and available online at | ||
* | ||
* http://www.dspace.org/license/ | ||
*/ | ||
package org.dspace.app.rest; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest; | ||
import org.junit.Test; | ||
|
||
/** | ||
* This class test the REST controller that returns information about the client user. | ||
* E.g. the client's IP address. | ||
* | ||
* @author Milan Majchrak (milan.majchrak at dataquest.sk) | ||
*/ | ||
public class ClarinUserInfoControllerIT extends AbstractControllerIntegrationTest { | ||
|
||
@Test | ||
public void getUserIPAddress() throws Exception { | ||
getClient().perform(get("/api/userinfo/ipaddress") | ||
.contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().json("{\"ipAddress\":\"127.0.0.1\"}")); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -10,31 +10,39 @@ | |
import static com.jayway.jsonpath.JsonPath.read; | ||
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath; | ||
import static org.dspace.app.rest.matcher.MetadataMatcher.matchMetadata; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest; | ||
import org.dspace.builder.CollectionBuilder; | ||
import org.dspace.builder.CommunityBuilder; | ||
import org.dspace.builder.EPersonBuilder; | ||
import org.dspace.builder.ItemBuilder; | ||
import org.dspace.builder.VersionBuilder; | ||
import org.dspace.builder.WorkspaceItemBuilder; | ||
import org.dspace.content.Collection; | ||
import org.dspace.content.Item; | ||
import org.dspace.content.MetadataValue; | ||
import org.dspace.content.WorkspaceItem; | ||
import org.dspace.content.service.ItemService; | ||
import org.dspace.content.service.WorkspaceItemService; | ||
import org.dspace.eperson.EPerson; | ||
import org.dspace.license.service.CreativeCommonsService; | ||
import org.dspace.services.ConfigurationService; | ||
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory; | ||
import org.dspace.xmlworkflow.storedcomponents.service.CollectionRoleService; | ||
import org.dspace.xmlworkflow.storedcomponents.service.XmlWorkflowItemService; | ||
import org.hamcrest.Matchers; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
|
@@ -64,6 +72,8 @@ public class ClarinWorkflowItemRestRepositoryIT extends AbstractControllerIntegr | |
|
||
@Autowired | ||
private CreativeCommonsService creativeCommonsService; | ||
@Autowired | ||
private XmlWorkflowItemService xmlWorkflowItemService; | ||
|
||
@Autowired | ||
private ItemService itemService; | ||
|
@@ -250,4 +260,64 @@ public void shouldAddNewHandleToItemMetadata() throws Exception { | |
WorkspaceItemBuilder.deleteWorkspaceItem(idWorkspaceItemRef.get()); | ||
} | ||
} | ||
|
||
|
||
@Test | ||
public void shouldCreateProvenanceMessageOnItemSubmit() throws Exception { | ||
context.turnOffAuthorisationSystem(); | ||
|
||
//** GIVEN ** | ||
//1. A community with one collection. | ||
parentCommunity = CommunityBuilder.createCommunity(context) | ||
.withName("Parent Community") | ||
.build(); | ||
|
||
//2. create a normal user to use as submitter | ||
EPerson submitter = EPersonBuilder.createEPerson(context) | ||
.withEmail("[email protected]") | ||
.withPassword("dspace") | ||
.build(); | ||
|
||
// Submitter group - allow deposit a new item without workflow | ||
Collection col1 = CollectionBuilder.createCollection(context, parentCommunity) | ||
.withName("Collection 2") | ||
.withSubmitterGroup(submitter) | ||
.build(); | ||
context.setCurrentUser(submitter); | ||
|
||
//3. a workspace item | ||
WorkspaceItem wsitem = WorkspaceItemBuilder.createWorkspaceItem(context, col1) | ||
.withTitle("Submission Item") | ||
.withIssueDate("2017-10-17") | ||
.grantLicense() | ||
.build(); | ||
|
||
context.restoreAuthSystemState(); | ||
|
||
// get the submitter auth token | ||
String authToken = getAuthToken(submitter.getEmail(), "dspace"); | ||
|
||
// submit the workspaceitem to start the workflow | ||
getClient(authToken) | ||
.perform(post(BASE_REST_SERVER_URL + "/api/workflow/workflowitems") | ||
.content("/api/submission/workspaceitems/" + wsitem.getID()) | ||
.contentType(textUriContentType)) | ||
.andExpect(status().isCreated()); | ||
|
||
// Load deposited item and check the provenance metadata | ||
Item depositedItem = itemService.find(context, wsitem.getItem().getID()); | ||
List<MetadataValue> mvList = itemService.getMetadata(depositedItem, "dc", "description", | ||
"provenance", Item.ANY); | ||
assertFalse(mvList.isEmpty()); | ||
|
||
// Check if the provenance contains the submitter info | ||
boolean containsSubmitterProvenance = false; | ||
for (MetadataValue mv: mvList) { | ||
if (mv.getValue().contains("Submitted by " + submitter.getEmail())) { | ||
containsSubmitterProvenance = true; | ||
break; | ||
} | ||
} | ||
assertThat(containsSubmitterProvenance, is(true)); | ||
} | ||
} |
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
Oops, something went wrong.