Commit e6e974df authored by Steinberg, Jan's avatar Steinberg, Jan
Browse files

following up

parent 1144bd55
......@@ -72,36 +72,35 @@ public class BundlesSourceResource {
/**
* POST /bundlesSources -> Create a new bundlesSource.
*/
@RequestMapping(value = "/bundlesSources",
method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/bundlesSources", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<BundlesSource> createBundlesSource(@RequestBody BundlesSource bundlesSource) throws URISyntaxException {
public ResponseEntity<BundlesSource> createBundlesSource(@RequestBody BundlesSource bundlesSource)
throws URISyntaxException {
log.debug("REST request to save BundlesSource : {}", bundlesSource);
if (bundlesSource.getId() != null) {
return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert("bundlesSource", "idexists", "A new bundlesSource cannot already have an ID")).body(null);
return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert("bundlesSource", "idexists",
"A new bundlesSource cannot already have an ID")).body(null);
}
// final String setSpec = getSetSpec(bundlesSource.getData());
BundlesSource result = bundlesSourceRepository.save(bundlesSource);
// if ( result.getType().equals(BundlesSourceType.XSLT_OAI_PMH) && null != setSpec) {
// if ( result.getType().equals(BundlesSourceType.XSLT_OAI_PMH) && null !=
// setSpec) {
// final String currentReference = result.getReference();
// result.setReference(currentReference + "___" + setSpec);
// result = bundlesSourceRepository.save(result);
// }
// else
if ( result.getType().equals(BundlesSourceType.XML_XSLT_SOURCE) ) {
result.setReference("xmlxslt-bundlessource-" + result.getId() );
if (result.getType().equals(BundlesSourceType.XML_XSLT_SOURCE)) {
result.setReference("xmlxslt-bundlessource-" + result.getId());
result = bundlesSourceRepository.save(result);
}
else if ( result.getType().equals(BundlesSourceType.BIBTEX_SOURCE) ) {
result.setReference("bibtex-bundlessource-" + result.getId() );
} else if (result.getType().equals(BundlesSourceType.BIBTEX_SOURCE)) {
result.setReference("bibtex-bundlessource-" + result.getId());
result = bundlesSourceRepository.save(result);
}
return ResponseEntity.created(new URI("/api/bundlesSources/" + result.getId()))
.headers(HeaderUtil.createEntityCreationAlert("bundlesSource", result.getId().toString()))
.body(result);
.headers(HeaderUtil.createEntityCreationAlert("bundlesSource", result.getId().toString())).body(result);
}
private String getSetSpec(String data, BundlesSourceType bundlesSourceType) {
......@@ -115,13 +114,13 @@ public class BundlesSourceResource {
}
/**
* POST /bundlesSources/forCurrentUser -> Create a new bundlesSource, setting its owner to currentUser.
* POST /bundlesSources/forCurrentUser -> Create a new bundlesSource, setting
* its owner to currentUser.
*/
@RequestMapping(value = "/bundlesSources/forCurrentUser",
method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/bundlesSources/forCurrentUser", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<BundlesSource> createBundlesSourceForCurrentUser(@RequestBody BundlesSource bundlesSource) throws URISyntaxException {
public ResponseEntity<BundlesSource> createBundlesSourceForCurrentUser(@RequestBody BundlesSource bundlesSource)
throws URISyntaxException {
bundlesSource.setOwner(userRepository.findOneByLogin(SecurityUtils.getCurrentUserLogin()).get());
log.debug("REST request to save BundlesSource={} for current user={}", bundlesSource);
return createBundlesSource(bundlesSource);
......@@ -130,11 +129,10 @@ public class BundlesSourceResource {
/**
* PUT /bundlesSources -> Updates an existing bundlesSource.
*/
@RequestMapping(value = "/bundlesSources",
method = RequestMethod.PUT,
produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/bundlesSources", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<BundlesSource> updateBundlesSource(@RequestBody BundlesSource bundlesSource) throws URISyntaxException {
public ResponseEntity<BundlesSource> updateBundlesSource(@RequestBody BundlesSource bundlesSource)
throws URISyntaxException {
log.debug("REST request to update BundlesSource : {}", bundlesSource);
if (bundlesSource.getId() == null) {
return createBundlesSource(bundlesSource);
......@@ -154,12 +152,9 @@ public class BundlesSourceResource {
/**
* GET /bundlesSources -> get all the bundlesSources.
*/
@RequestMapping(value = "/bundlesSources",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/bundlesSources", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<List<BundlesSource>> getAllBundlesSources(Pageable pageable)
throws URISyntaxException {
public ResponseEntity<List<BundlesSource>> getAllBundlesSources(Pageable pageable) throws URISyntaxException {
log.debug("REST request to get a page of BundlesSources");
Page<BundlesSource> page = bundlesSourceRepository.findAll(pageable);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/bundlesSources");
......@@ -169,15 +164,12 @@ public class BundlesSourceResource {
/**
* GET /bundlesSources -> get all the bundlesSources Scoped on the current User.
*/
@RequestMapping(value = "/bundlesSources/forCurrentUser",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/bundlesSources/forCurrentUser", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<List<BundlesSource>> getAllBundlesSourcesForCurrentUser()
throws URISyntaxException {
public ResponseEntity<List<BundlesSource>> getAllBundlesSourcesForCurrentUser() throws URISyntaxException {
log.debug("REST request to get a page of BundlesSources");
List<BundlesSource> result;
if ( SecurityUtils.isCurrentUserInRole(AuthoritiesConstants.ADMIN) ) {
if (SecurityUtils.isCurrentUserInRole(AuthoritiesConstants.ADMIN)) {
result = bundlesSourceRepository.findAll();
} else {
result = bundlesSourceRepository.findByOwnerIsCurrentUser();
......@@ -188,49 +180,37 @@ public class BundlesSourceResource {
/**
* GET /bundlesSources/:id -> get the "id" bundlesSource.
*/
@RequestMapping(value = "/bundlesSources/{id}",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/bundlesSources/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<BundlesSource> getBundlesSource(@PathVariable Long id) {
log.debug("REST request to get BundlesSource : {}", id);
BundlesSource bundlesSource = bundlesSourceRepository.findOne(id);
return Optional.ofNullable(bundlesSource)
.map(result -> new ResponseEntity<>(
result,
HttpStatus.OK))
return Optional.ofNullable(bundlesSource).map(result -> new ResponseEntity<>(result, HttpStatus.OK))
.orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
}
/**
* GET /bundlesSources/:id/bundles -> get all bundles for "id" bundlesSource.
*/
@RequestMapping(value = "/bundlesSources/{id}/bundles",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/bundlesSources/{id}/bundles", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<List<Bundle>> getBundlesSourceBundles(@PathVariable Long id) {
log.debug("REST request to get BundlesSource {}'s bundles", id);
List<Bundle> bundles = bundleRepository.findByBundlesSourceId(id);
return Optional.ofNullable(bundles)
.map(result -> new ResponseEntity<>(
result,
HttpStatus.OK))
return Optional.ofNullable(bundles).map(result -> new ResponseEntity<>(result, HttpStatus.OK))
.orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
}
/**
* PUT /bundlesSources/:id/data -> update bundlesSource.data.
*/
@RequestMapping(value = "/bundlesSources/{id}/data",
method = RequestMethod.PUT,
produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/bundlesSources/{id}/data", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<Void> updateBundlesSourceData(@PathVariable Long id, @RequestBody String data) {
log.debug("REST request to put new data=\n{}\n into BundlesSource={} ", data, id);
ResponseEntity<Void> result;
BundlesSource bundlesSource = bundlesSourceRepository.findOne(id);
if (null != bundlesSource && null != bundlesSource.getType() ) {
if (null != bundlesSource && null != bundlesSource.getType()) {
String sanitizedData = sanitizeData(data, bundlesSource.getType());
bundlesSource.setData(sanitizedData);
bundlesSourceRepository.save(bundlesSource);
......@@ -244,11 +224,10 @@ public class BundlesSourceResource {
/**
* PUT /bundlesSources/:id/data -> update bundlesSource.metadataTransformer.
*/
@RequestMapping(value = "/bundlesSources/{id}/metadataTransformer",
method = RequestMethod.PUT,
produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/bundlesSources/{id}/metadataTransformer", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<Void> updateBundlesSourceMetadataTransformer(@PathVariable Long id, @RequestBody Long metadataTransformerId) {
public ResponseEntity<Void> updateBundlesSourceMetadataTransformer(@PathVariable Long id,
@RequestBody Long metadataTransformerId) {
log.debug("REST request to associate new metadataTransformer for BundlesSource : {}", id);
ResponseEntity<Void> result;
BundlesSource bundlesSource = bundlesSourceRepository.findOne(id);
......@@ -257,27 +236,23 @@ public class BundlesSourceResource {
bundlesSource.setMetadataTransformer(mdt);
bundlesSource = bundlesSourceRepository.save(bundlesSource);
result = ResponseEntity.ok().build();
}
else {
} else {
result = ResponseEntity.notFound().build();
}
return result;
}
@RequestMapping(value = "/bundlesSources/{id}/reference",
method = RequestMethod.PUT,
produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/bundlesSources/{id}/reference", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<Void> updateBundlesSourceReference(@PathVariable Long id, @RequestBody String reference) {
log.debug("REST request to put new reference={} into BundlesSource={} ", reference, id);
ResponseEntity<Void> result;
BundlesSource bundlesSource = bundlesSourceRepository.findOne(id);
if (null != bundlesSource && null != bundlesSource.getType() ) {
if (null != bundlesSource && null != bundlesSource.getType()) {
bundlesSource.setReference(reference);
bundlesSource = bundlesSourceRepository.save(bundlesSource);
result = ResponseEntity.ok().build();
}
else {
} else {
result = ResponseEntity.notFound().build();
}
return result;
......@@ -286,19 +261,16 @@ public class BundlesSourceResource {
/**
* DELETE /bundlesSources/:id -> delete the "id" bundlesSource.
*/
@RequestMapping(value = "/bundlesSources/{id}",
method = RequestMethod.DELETE,
produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/bundlesSources/{id}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<Void> deleteBundlesSource(@PathVariable Long id) {
log.debug("REST request to delete BundlesSource : {}", id);
bundlesSourceRepository.delete(id);
return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert("bundlesSource", id.toString())).build();
return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert("bundlesSource", id.toString()))
.build();
}
@RequestMapping(value = "/bundlesSources/{id}/harvest",
method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/bundlesSources/{id}/harvest", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<Void> harvestBundlesSource(@PathVariable Long id) {
ResponseEntity<Void> result;
......@@ -308,14 +280,17 @@ public class BundlesSourceResource {
final String setSpec = getSetSpec(bundlesSource.getData(), bundlesSource.getType());
if (null != setSpec) {
final String referenceOfBS = bundlesSource.getReference();
if (bundlesSource.getType() == BundlesSourceType.XSLT_OAI_PMH) {
bundlesSource.setReference(referenceOfBS + "___" + setSpec);
} else {
bundlesSource.setReference(referenceOfBS);
}
bundlesSourceRepository.save(bundlesSource);
}
FeedingContext feedingContext = feedingContextFactory.getFeedingContext(bundlesSource);
feederService.feed(feedingContext);
result = ResponseEntity.accepted().build();
}
else {
} else {
result = ResponseEntity.notFound().build();
}
return result;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment