-
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.
Merge pull request #121 from diging/develop
prepare release
- Loading branch information
Showing
32 changed files
with
990 additions
and
87 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
16 changes: 16 additions & 0 deletions
16
giles-eco/src/main/java/edu/asu/diging/gilesecosystem/web/api/util/IResponseHelper.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,16 @@ | ||
package edu.asu.diging.gilesecosystem.web.api.util; | ||
|
||
import java.util.Map; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
public interface IResponseHelper { | ||
/** | ||
* Generates a ResponseEntity with a JSON body based on the given map of messages and HTTP status. | ||
* @param msgs a map of messages where the keys represent message identifiers and the values represent message content | ||
* @param status the HTTP status code to be set in the response | ||
* @return a ResponseEntity object with JSON content and the specified HTTP status | ||
*/ | ||
public abstract ResponseEntity<String> generateResponse(Map<String, String> msgs, HttpStatus status); | ||
} |
48 changes: 48 additions & 0 deletions
48
giles-eco/src/main/java/edu/asu/diging/gilesecosystem/web/api/util/impl/ResponseHelper.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,48 @@ | ||
package edu.asu.diging.gilesecosystem.web.api.util.impl; | ||
|
||
import java.io.IOException; | ||
import java.io.StringWriter; | ||
import java.util.Map; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
|
||
import edu.asu.diging.gilesecosystem.septemberutil.properties.MessageType; | ||
import edu.asu.diging.gilesecosystem.septemberutil.service.ISystemMessageHandler; | ||
import edu.asu.diging.gilesecosystem.web.api.util.IResponseHelper; | ||
|
||
@Component | ||
public class ResponseHelper implements IResponseHelper { | ||
|
||
@Autowired | ||
private ISystemMessageHandler messageHandler; | ||
|
||
@Override | ||
public ResponseEntity<String> generateResponse(Map<String, String> msgs, | ||
HttpStatus status) { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
mapper.enable(SerializationFeature.INDENT_OUTPUT); | ||
ObjectNode root = mapper.createObjectNode(); | ||
for (String key : msgs.keySet()) { | ||
root.put(key, msgs.get(key)); | ||
} | ||
|
||
StringWriter sw = new StringWriter(); | ||
try { | ||
mapper.writeValue(sw, root); | ||
} catch (IOException e) { | ||
messageHandler.handleMessage("Could not write json.", e, MessageType.ERROR); | ||
return new ResponseEntity<String>( | ||
"{\"errorMsg\": \"Could not write json result.\", \"errorCode\": \"errorCode\": \"500\" }", | ||
HttpStatus.INTERNAL_SERVER_ERROR); | ||
} | ||
|
||
return new ResponseEntity<String>(sw.toString(), status); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...src/main/java/edu/asu/diging/gilesecosystem/web/api/v2/V2ReprocessDocumentController.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,71 @@ | ||
package edu.asu.diging.gilesecosystem.web.api.v2; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
|
||
import edu.asu.diging.gilesecosystem.util.properties.IPropertiesManager; | ||
import edu.asu.diging.gilesecosystem.web.api.util.IResponseHelper; | ||
import edu.asu.diging.gilesecosystem.web.config.CitesphereToken; | ||
import edu.asu.diging.gilesecosystem.web.core.citesphere.ICitesphereConnector; | ||
import edu.asu.diging.gilesecosystem.web.core.model.IDocument; | ||
import edu.asu.diging.gilesecosystem.web.core.model.IUpload; | ||
import edu.asu.diging.gilesecosystem.web.core.service.core.ITransactionalDocumentService; | ||
import edu.asu.diging.gilesecosystem.web.core.service.core.ITransactionalUploadService; | ||
import edu.asu.diging.gilesecosystem.web.core.service.properties.Properties; | ||
import edu.asu.diging.gilesecosystem.web.core.service.reprocessing.IReprocessingService; | ||
import edu.asu.diging.gilesecosystem.web.core.users.CitesphereUser; | ||
|
||
@Controller | ||
public class V2ReprocessDocumentController { | ||
@Autowired | ||
private IReprocessingService reprocessingService; | ||
|
||
@Autowired | ||
private ITransactionalDocumentService documentService; | ||
|
||
@Autowired | ||
private IResponseHelper responseHelper; | ||
|
||
@Autowired | ||
private IPropertiesManager propertyManager; | ||
|
||
@Autowired | ||
private ITransactionalUploadService uploadService; | ||
|
||
@Autowired | ||
private ICitesphereConnector citesphereConnector; | ||
|
||
@Value("${giles_check_upload_endpoint_v2}") | ||
private String uploadEndpoint; | ||
|
||
@RequestMapping(value = "/api/v2/resources/documents/{documentId}/reprocess", method = RequestMethod.POST, produces = "application/json;charset=UTF-8") | ||
public ResponseEntity<String> reprocessDocument(@PathVariable("documentId") String documentId, CitesphereToken citesphereToken) { | ||
IDocument document = documentService.getDocument(documentId); | ||
Map<String, String> msgs = new HashMap<String, String>(); | ||
if (document == null) { | ||
msgs.put("errorMsg", "Document with id: " + documentId + " does not exist."); | ||
msgs.put("errorCode", "404"); | ||
return responseHelper.generateResponse(msgs, HttpStatus.NOT_FOUND); | ||
} | ||
if (!citesphereConnector.hasAccess(document.getId(), ((CitesphereUser)citesphereToken.getPrincipal()).getUsername())) { | ||
Map<String, String> unauthorizedMsgs = new HashMap<String, String>(); | ||
unauthorizedMsgs.put("errorMsg", "User is not authorized to reprocess the document with id " + document.getId()); | ||
unauthorizedMsgs.put("errorCode", "403"); | ||
return responseHelper.generateResponse(unauthorizedMsgs, HttpStatus.FORBIDDEN); | ||
} | ||
reprocessingService.reprocessDocument(document); | ||
IUpload upload = uploadService.getUpload(document.getUploadId()); | ||
msgs.put("id", documentId); | ||
msgs.put("checkUrl", propertyManager.getProperty(Properties.GILES_URL) + uploadEndpoint + upload.getUploadProgressId()); | ||
return responseHelper.generateResponse(msgs, HttpStatus.OK); | ||
} | ||
} |
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
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.