Commit cbc9c3e6 authored by Matija Obreza's avatar Matija Obreza
Browse files

Documented the accession Images API, using the new file-repository

parent f28c4c20
......@@ -23,3 +23,4 @@ npm-debug.log
.classpath
.settings
.pmd
node_tmp
[[chApiImg]]
== Managing Accession Images
Institutes can upload accession images to Genesys repository. Genesys will store
and maintain images and metadata provided by institutes and display the images
with accession passport data.
[NOTE]
.Unique ACCENUMB
=====================================================================
Genesys supports image galleries only for institutes that use unique ACCENUMB
within their institute.
=====================================================================
Managing accession images in Genesys is done through methods available in
*/api/v0/img/{instCode}/* namespace.
=== Listing existing galleries
To list existing accession image galleries for the INSTCODE, you must have the
`WRITE` or `CREATE` permission on the institute record. Issue a GET request to
*/api/v0/img/{instCode}/_galleries* endpoint:
include::{snippets}/img-instgallery-list/curl-request.adoc[]
==== Path parameters
include::{snippets}/img-instgallery-list/path-parameters.adoc[]
==== Request parameters
include::{snippets}/img-instgallery-list/request-parameters.adoc[]
==== Server response
The object returned by Genesys contains pagination information and basic image
gallery data in the `content` element:
[source,json,linenums]
----
{
"content": [{
"uuid": "4422e87e-52fe-38ef-b04a-079e663dd3da",
"version": 0,
"instCode": "XXX001",
"instEmail": "institute@localhost",
"state": 0,
"createdDate": null,
"lastModifiedDate": null,
"lastReminderDate": null
}], <1>
"last": true,
"totalElements": 1, <2>
"totalPages": 1, <3>
"size": 10, <4>
"number": 0,
"sort": [{
"direction": "DESC",
"property": "createdDate",
"ignoreCase": false,
"nullHandling": "NATIVE",
"ascending": false
}],
"first": true,
"numberOfElements": 1 <5>
}
----
<1> Array containing request information
<2> Number of elements in the Genesys database
<3> Number of pages
<4> Page size
<5> Number of elements in the `content` array
include::{snippets}/requests-inst-list/response-fields.adoc[]
=== Accepted image formats
Genesys allows for images in JPG and PNG format.
=== Adding images to accessions
To add images to an accession you must first upload the image to Genesys with a
PUT request with the image bytes in the request body:
[source,bash]
----
$ curl 'https://sandbox.genesys-pgr.org/api/v0/img/XXX001/acn/ACC001/?originalFilename=IMG0012.jpg' -i -X PUT -H 'Content-Type: image/jpeg' -d @path/to/IMG0012.jpg
----
The request Content-Type header must be set to the image content type (e.g.
`image/png` or `image/jpeg`).
==== Path parameters
include::{snippets}/img-instgallery-put/path-parameters.adoc[]
==== Request parameters
include::{snippets}/img-instgallery-put/request-parameters.adoc[]
==== Server response
As Genesys accepts the image data, it will create a blank image metadata record
and return the detailed image data, including the image *UUID* which you is
required for subsequent updates of the image metadata or the image bytes.
[source,json,linenums]
----
{
"id": 1,
"contentType": "image/jpeg",
"format": "image/jpeg",
"uuid": "16648001-72b5-4295-ad29-169a414ee8f1",
"identifier": "urn:uuid:16648001-72b5-4295-ad29-569a414ee8f1",
"originalFilename": "maize.jpg",
"extension": ".jpg",
"path": "/accessions/XXX001/acn/ACC001/",
"filename": "16648001-72b5-4295-ad29-569a414ee8f1.jpg",
"url": "/accessions/XXX001/acn/ACC001/16648001-72b5-4295-ad29-569a414ee8f1.jpg"
"sha1Sum": "160599e1ccd66e132a9b92bc845a9591fe948586",
"md5Sum": "c1887df421746e30a41b898956ea1f3e",
"width": 640,
"height": 427,
"orientation": "LANDSCAPE",
"title": null,
"subject": null,
"description": null,
"creator": null,
"created": null,
"rightsHolder": null,
"accessRights": null,
"license": null,
"extent": null,
"bibliographicCitation": null,
"createdDate": null,
"lastModifiedDate": null,
"originalUrl": null,
"dateRetrieved": null,
"dateSubmitted": null,
"modified": null,
}
----
You will observe that most metadata is `null`, but the image bytes are already
stored in Genesys repository. Genesys also determines the image `width`, `height`
and `orientation` from the image.
include::{snippets}/img-instgallery-put/response-fields.adoc[]
=== Updating image metadata
After a successful upload of the image to Genesys repository, you are able to
manage the image metadata.
[source,json,linenums]
----
{
"title": "Leaf of ACC001",
"subject": "ACC001",
"description": "Image of leaf of ACC001 taken ...",
"creator": "John Doe",
"rightsHolder": "International Institute of Accessions (IIA)",
"accessRights": "Access rights",
"license": "https://creativecommons.org/publicdomain/zero/1.0/",
"bibliographicCitation": "Genesys Museum in Bonn. Digital image. Accession Imagery. Genesys. Web. 9 August 2016."
}
----
include::{snippets}/img-instgallery-metadata-put/request-fields.adoc[]
An example `curl` request is:
include::{snippets}/img-instgallery-metadata-put/curl-request.adoc[]
==== Path parameters
include::{snippets}/img-instgallery-metadata-put/path-parameters.adoc[]
==== Response fields
Server response
[source,json,linenums]
----
{
"id": 1,
"uuid": "1e23549e-a882-40b4-abc8-0a4708ba7ff3",
"path": "/accessions/XXX001/acn/ACC001/",
"originalFilename": "maize.jpg",
"extension": ".jpg",
"title": "Leaf of ACC001",
"subject": "ACC001",
"description": "Image of leaf of ACC001 taken ...",
"creator": "John Doe",
"created": null,
"rightsHolder": "International Institute of Accessions (IIA)",
"accessRights": "Access rights",
"license": "https://creativecommons.org/publicdomain/zero/1.0/",
"contentType": "image/jpeg",
"extent": null,
"bibliographicCitation": "Genesys Museum in Bonn. Digital image. Accession Imagery. Genesys. Web. 9 August 2016.",
"createdDate": null,
"lastModifiedDate": null,
"originalUrl": null,
"dateRetrieved": null,
"sha1Sum": "160599e1ccd66e132a9b92bc845a9591fe948586",
"md5Sum": "c1887df421746e30a41b898956ea1f3e",
"width": 640,
"height": 427,
"orientation": "LANDSCAPE",
"identifier": "urn:uuid:1e23549e-a882-40b4-abc8-0a4708ba7ff3",
"dateSubmitted": null,
"modified": null,
"format": "image/jpeg",
"url": "/accessions/XXX001/acn/ACC001/1e23549e-a882-40b4-abc8-0a4708ba7ff3.jpg",
"filename": "1e23549e-a882-40b4-abc8-0a4708ba7ff3.jpg"
}
----
include::{snippets}/img-instgallery-metadata-put/response-fields.adoc[]
......@@ -20,8 +20,9 @@ In this manual, all URLs are pointing to the Genesys sandbox environment at http
include::api/security.adoc[]
include::api/accession.adoc[]
include::api/crop.adoc[]
include::api/images.adoc[]
include::api/requests.adoc[]
include::api/crop.adoc[]
== Acknowledgements
......
......@@ -24,6 +24,7 @@ import org.genesys2.server.filerepository.InvalidRepositoryPathException;
import org.genesys2.server.filerepository.NoSuchRepositoryFileException;
import org.genesys2.server.filerepository.model.ImageGallery;
import org.genesys2.server.filerepository.model.RepositoryImage;
import org.genesys2.server.filerepository.model.RepositoryImageData;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.FaoInstitute;
import org.springframework.data.domain.Page;
......@@ -38,7 +39,7 @@ public interface InstituteFilesService {
RepositoryImage getImage(FaoInstitute institute, Accession accession, UUID uuid) throws NoSuchRepositoryFileException;
RepositoryImage updateImageMetadata(FaoInstitute institute, Accession accession, RepositoryImage repositoryImage) throws NoSuchRepositoryFileException;
RepositoryImage updateImageMetadata(FaoInstitute institute, Accession accession, UUID uuid, RepositoryImageData repositoryImage) throws NoSuchRepositoryFileException;
byte[] getFileBytes(FaoInstitute institute, Accession accession, RepositoryImage repositoryImage) throws NoSuchRepositoryFileException;
......@@ -50,4 +51,7 @@ public interface InstituteFilesService {
RepositoryImage updateImage(FaoInstitute institute, Accession accession, RepositoryImage repositoryImage, String contentType, byte[] bytes) throws NoSuchRepositoryFileException, IOException;
RepositoryImage deleteImage(FaoInstitute institute, Accession accession, RepositoryImage repositoryImage) throws NoSuchRepositoryFileException, IOException;
}
......@@ -285,8 +285,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
} else {
try {
Accession accnByAlias = accessionAliasRepository.findAccession(aid3.getHoldingInstitute(), aid3.getAccessionName(),
AccessionAlias.AliasType.OTHERNUMB.getId());
Accession accnByAlias = accessionAliasRepository.findAccession(aid3.getHoldingInstitute(), aid3.getAccessionName(), AccessionAlias.AliasType.OTHERNUMB.getId());
if (accnByAlias != null) {
LOG.info("Found accession by alias " + accnByAlias);
......@@ -773,7 +772,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
if (LOG.isDebugEnabled())
LOG.debug("Updating " + accession);
System.err.println("Saving " + accession + " ST=" + accession.getStorage());
LOG.debug("Saving " + accession + " ST=" + accession.getStorage());
AccessionData res = null;
if (accession instanceof AccessionHistoric) {
res = accessionHistoricRepository.save((AccessionHistoric) accession);
......@@ -1111,7 +1110,8 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
zos.putNextEntry(metaEntry);
final BufferedWriter osw = new BufferedWriter(new OutputStreamWriter(zos));
osw.write("<?xml version='1.0' encoding='utf-8'?>\n");
osw.write("<archive xmlns=\"http://rs.tdwg.org/dwc/text/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://rs.tdwg.org/dwc/text/ http://rs.tdwg.org/dwc/text/tdwg_dwc_text.xsd\">\n");
osw.write(
"<archive xmlns=\"http://rs.tdwg.org/dwc/text/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://rs.tdwg.org/dwc/text/ http://rs.tdwg.org/dwc/text/tdwg_dwc_text.xsd\">\n");
osw.write("<core encoding=\"UTF-8\" fieldsTerminatedBy=\",\" linesTerminatedBy=\"\\n\" fieldsEnclosedBy=\"&quot;\" ignoreHeaderLines=\"0\">\n");
osw.write("\t<files><location>core.csv</location></files>\n");
osw.write("\t<id index=\"0\" />\n");
......@@ -1206,8 +1206,8 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
private void writeAccessionsCore(final AppliedFilters filters, ZipOutputStream zos) throws IOException {
@SuppressWarnings("resource")
final CSVWriter csv = new CSVWriter(new BufferedWriter(new OutputStreamWriter(zos)), ',', '"', '\\', "\n");
csv.writeNext(new String[] { "genesysId", "uuid", "instCode", "acceNumb", "genus", "species", "fullTaxa", "orgCty", "acqSrc", "acqDate", "mlsStat",
"available", "historic", "storage", "sampStat", "duplSite", "createdBy", "createdDate", "lastModifiedBy", "lastModifiedDate" });
csv.writeNext(new String[] { "genesysId", "uuid", "instCode", "acceNumb", "genus", "species", "fullTaxa", "orgCty", "acqSrc", "acqDate", "mlsStat", "available", "historic", "storage",
"sampStat", "duplSite", "createdBy", "createdDate", "lastModifiedBy", "lastModifiedDate" });
final ResultSetHelper csvResultsetHelper = new CSVResultSetHelper();
......@@ -1297,8 +1297,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
private void writeAccessionsColl(final AppliedFilters filters, ZipOutputStream zos) throws IOException {
@SuppressWarnings("resource")
final CSVWriter csv = new CSVWriter(new BufferedWriter(new OutputStreamWriter(zos)), ',', '"', '\\', "\n");
csv.writeNext(new String[] { "genesysId", "collMissId", "collNumb", "collDate", "collSrc", "collSite", "collCode", "collName", "collInstAddress",
"version" });
csv.writeNext(new String[] { "genesysId", "collMissId", "collNumb", "collDate", "collSrc", "collSite", "collCode", "collName", "collInstAddress", "version" });
final ResultSetHelper csvResultsetHelper = new ResultSetHelperService();
......@@ -1378,7 +1377,8 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
zos.putNextEntry(metaEntry);
final BufferedWriter osw = new BufferedWriter(new OutputStreamWriter(zos));
osw.write("<?xml version='1.0' encoding='utf-8'?>\n");
osw.write("<archive xmlns=\"http://rs.tdwg.org/dwc/text/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://rs.tdwg.org/dwc/text/ http://rs.tdwg.org/dwc/text/tdwg_dwc_text.xsd\">\n");
osw.write(
"<archive xmlns=\"http://rs.tdwg.org/dwc/text/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://rs.tdwg.org/dwc/text/ http://rs.tdwg.org/dwc/text/tdwg_dwc_text.xsd\">\n");
osw.write("<core encoding=\"UTF-8\" fieldsTerminatedBy=\",\" linesTerminatedBy=\"\\n\" fieldsEnclosedBy=\"&quot;\" ignoreHeaderLines=\"0\">\n");
osw.write("\t<files><location>core.csv</location></files>\n");
osw.write("\t<id index=\"0\" />\n");
......
......@@ -27,6 +27,7 @@ import org.genesys2.server.filerepository.NoSuchRepositoryFileException;
import org.genesys2.server.filerepository.model.ImageGallery;
import org.genesys2.server.filerepository.model.RepositoryFile;
import org.genesys2.server.filerepository.model.RepositoryImage;
import org.genesys2.server.filerepository.model.RepositoryImageData;
import org.genesys2.server.filerepository.service.ImageGalleryService;
import org.genesys2.server.filerepository.service.RepositoryService;
import org.genesys2.server.model.genesys.Accession;
......@@ -83,8 +84,7 @@ public class InstituteFilesServiceImpl implements InstituteFilesService {
public ImageGallery createImageGallery(FaoInstitute institute, Accession accession) {
final String path = getGalleryPath(institute, accession);
return this.imageGalleryService.createImageGallery(path, String.format(ACCESSION_GALLERY_TITLE_FORMAT, accession.getAccessionName()),
ACCESSION_GALLERY_DESCRIPTION);
return this.imageGalleryService.createImageGallery(path, String.format(ACCESSION_GALLERY_TITLE_FORMAT, accession.getAccessionName()), ACCESSION_GALLERY_DESCRIPTION);
}
@Override
......@@ -103,15 +103,18 @@ public class InstituteFilesServiceImpl implements InstituteFilesService {
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#institute, 'WRITE') or hasPermission(#institute, 'CREATE')")
public RepositoryImage updateImageMetadata(final FaoInstitute institute, final Accession accession, final RepositoryImage repositoryImage)
throws NoSuchRepositoryFileException {
return this.repositoryService.updateMetadata(repositoryImage);
public RepositoryImage updateImageMetadata(final FaoInstitute institute, Accession accession, final UUID uuid, final RepositoryImageData imageData) throws NoSuchRepositoryFileException {
final RepositoryFile repositoryFile = this.repositoryService.getFile(uuid);
if (!repositoryFile.getPath().equals(getGalleryPath(institute, accession))) {
LOG.warn(repositoryFile.getPath() + "!=" + getGalleryPath(institute, accession));
throw new ResourceNotFoundException("No such thing");
}
return this.repositoryService.updateMetadata(repositoryFile.getUuid(), imageData);
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#institute, 'WRITE') or hasPermission(#institute, 'CREATE')")
public byte[] getFileBytes(final FaoInstitute institute, final Accession accession, final RepositoryImage repositoryImage)
throws NoSuchRepositoryFileException {
public byte[] getFileBytes(final FaoInstitute institute, final Accession accession, final RepositoryImage repositoryImage) throws NoSuchRepositoryFileException {
return this.repositoryService.getFileBytes(getGalleryPath(institute, accession), repositoryImage.getFilename());
}
......@@ -129,4 +132,10 @@ public class InstituteFilesServiceImpl implements InstituteFilesService {
return repositoryService.updateBytes(repositoryImage, contentType, data);
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#institute, 'ADMINISTRATE') or hasPermission(#institute, 'DELETE')")
public RepositoryImage deleteImage(FaoInstitute institute, Accession accession, RepositoryImage repositoryImage) throws NoSuchRepositoryFileException, IOException {
return repositoryService.removeImage(repositoryImage);
}
}
......@@ -18,7 +18,6 @@ package org.genesys2.server.servlet.controller.admin;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
......@@ -32,6 +31,7 @@ import org.genesys2.server.filerepository.InvalidRepositoryFileDataException;
import org.genesys2.server.filerepository.InvalidRepositoryPathException;
import org.genesys2.server.filerepository.NoSuchRepositoryFileException;
import org.genesys2.server.filerepository.model.RepositoryFile;
import org.genesys2.server.filerepository.model.RepositoryFileData;
import org.genesys2.server.filerepository.service.ImageGalleryService;
import org.genesys2.server.filerepository.service.RepositoryService;
import org.genesys2.server.servlet.controller.BaseController;
......@@ -124,18 +124,11 @@ public class RepositoryController extends BaseController {
}
@RequestMapping(value = "/update", method = RequestMethod.POST)
public String updateMetadata(@ModelAttribute RepositoryFile repositoryFile, @RequestParam String uuid, RedirectAttributes redirectAttributes)
public String updateMetadata(@ModelAttribute RepositoryFileData fileData, @RequestParam String uuid, RedirectAttributes redirectAttributes)
throws NoSuchRepositoryFileException {
RepositoryFile updatedFile = repositoryService.getFile(UUID.fromString(uuid));
try {
updateMetadata(repositoryFile, updatedFile);
} catch (ParseException e) {
LOG.error("Incorrect date format. Should be 'yyyy-MM-dd HH:mm:ss'.", e);
redirectAttributes.addFlashAttribute("errorMessage", "Incorrect date format. Should be 'yyyy-MM-dd HH:mm:ss'.");
redirectAttributes.addAttribute("uuid", updatedFile.getUuid().toString());
return "redirect:" + CONTROLLER_PATH + "/edit";
}
updatedFile = repositoryService.updateMetadata(updatedFile);
updatedFile = repositoryService.updateMetadata(updatedFile.getUuid(), fileData);
return "redirect:" + CONTROLLER_PATH + "/files" + updatedFile.getPath();
}
......@@ -154,21 +147,4 @@ public class RepositoryController extends BaseController {
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
}
private void updateMetadata(RepositoryFile originalFile, RepositoryFile updatedFile) throws ParseException {
updatedFile.setTitle(originalFile.getTitle());
updatedFile.setSubject(originalFile.getSubject());
updatedFile.setDescription(originalFile.getDescription());
updatedFile.setCreator(originalFile.getCreator());
updatedFile.setCreated(originalFile.getCreated());
updatedFile.setRightsHolder(originalFile.getRightsHolder());
updatedFile.setAccessRights(originalFile.getAccessRights());
updatedFile.setLicense(originalFile.getLicense());
updatedFile.setContentType(originalFile.getContentType());
updatedFile.setExtent(originalFile.getExtent());
updatedFile.setOriginalFilename(originalFile.getOriginalFilename());
updatedFile.setBibliographicCitation(originalFile.getBibliographicCitation());
updatedFile.setCreatedDate(originalFile.getCreatedDate());
updatedFile.setLastModifiedDate(originalFile.getLastModifiedDate());
}
}
......@@ -31,6 +31,7 @@ import org.genesys2.server.filerepository.InvalidRepositoryPathException;
import org.genesys2.server.filerepository.NoSuchRepositoryFileException;
import org.genesys2.server.filerepository.model.ImageGallery;
import org.genesys2.server.filerepository.model.RepositoryImage;
import org.genesys2.server.filerepository.model.RepositoryImageData;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.GenesysService;
......@@ -47,6 +48,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
......@@ -76,15 +78,15 @@ public class InstituteGalleriesController extends RestController {
/**
* List existing image galleries for INSTCODE
*/
@RequestMapping(value = "/{instCode}/_galleries/{page:\\d+}", method = { RequestMethod.GET }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody Page<ImageGallery> listAccessionGalleries(@PathVariable("instCode") final String instCode, @PathVariable("page") final int page) {
@RequestMapping(value = "/{instCode}/_galleries", method = { RequestMethod.GET }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody Page<ImageGallery> listAccessionGalleries(@PathVariable("instCode") final String instCode, @RequestParam(name = "page", required = false, defaultValue = "1") final int page) {
final FaoInstitute institute = this.instituteService.findInstitute(instCode);
if (institute == null) {
throw new ResourceNotFoundException();
}
LOG.info("Listing galleryies for institute=" + institute);
LOG.info("Listing galleries for institute=" + institute);
// TODO no images!
return instituteFilesService.listImageGalleries(institute, new PageRequest(page, 50));
......@@ -96,8 +98,7 @@ public class InstituteGalleriesController extends RestController {
* @throws NonUniqueAccessionException
*/
@RequestMapping(value = "/{instCode}/acn/{acceNumb:.+}", method = { RequestMethod.GET }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody List<UUID> listAccessionGallery(@PathVariable("instCode") final String instCode, @PathVariable("acceNumb") final String acceNumb)
throws NonUniqueAccessionException {
public @ResponseBody List<UUID> listAccessionGallery(@PathVariable("instCode") final String instCode, @PathVariable("acceNumb") final String acceNumb) throws NonUniqueAccessionException {
final FaoInstitute institute = this.instituteService.findInstitute(instCode);
final Accession accession = this.genesysService.getAccession(instCode, acceNumb);
......@@ -126,9 +127,9 @@ public class InstituteGalleriesController extends RestController {
* @throws NonUniqueAccessionException
*/
@RequestMapping(value = "/{instCode}/acn/{acceNumb:.+}/{uuid}/_metadata", method = { RequestMethod.PUT }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody RepositoryImage updateImageMetadata(final HttpServletRequest request, final HttpServletResponse response,
@PathVariable("instCode") final String instCode, @PathVariable("acceNumb") final String acceNumb, @PathVariable("uuid") final UUID uuid,
@ModelAttribute final RepositoryImage repositoryImage) throws IOException, NonUniqueAccessionException {
public @ResponseBody RepositoryImage updateImageMetadata(final HttpServletRequest request, final HttpServletResponse response, @PathVariable("instCode") final String instCode,
@PathVariable("acceNumb") final String acceNumb, @PathVariable("uuid") final UUID uuid, @RequestBody final RepositoryImageData imageData)
throws IOException, NonUniqueAccessionException {
final FaoInstitute institute = this.instituteService.findInstitute(instCode);
final Accession accession = this.genesysService.getAccession(instCode, acceNumb);
......@@ -145,7 +146,7 @@ public class InstituteGalleriesController extends RestController {
throw new ResourceNotFoundException("No such thing");
}
return this.instituteFilesService.updateImageMetadata(institute, accession, repositoryImage);
return this.instituteFilesService.updateImageMetadata(institute, accession, existingRepositoryImage.getUuid(), imageData);
} catch (final NoSuchRepositoryFileException e) {
LOG.warn("404 - No such repository file ", e);
......@@ -160,9 +161,8 @@ public class InstituteGalleriesController extends RestController {
* @throws NonUniqueAccessionException
*/
@RequestMapping(value = "/{instCode}/acn/{acceNumb:.+}/{uuid}/_metadata", method = { RequestMethod.GET }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody RepositoryImage getImageMetadata(final HttpServletRequest request, final HttpServletResponse response,
@PathVariable("instCode") final String instCode, @PathVariable("acceNumb") final String acceNumb, @PathVariable("uuid") final UUID uuid)
throws IOException, NonUniqueAccessionException {
public @ResponseBody RepositoryImage getImageMetadata(final HttpServletRequest request, final HttpServletResponse response, @PathVariable("instCode") final String instCode,
@PathVariable("acceNumb") final String acceNumb, @PathVariable("uuid") final UUID uuid) throws IOException, NonUniqueAccessionException {
final FaoInstitute institute = this.instituteService.findInstitute(instCode);
final Accession accession = this.genesysService.getAccession(instCode, acceNumb);
......@@ -194,8 +194,8 @@ public class InstituteGalleriesController extends RestController {
* @throws NonUniqueAccessionException
*/
@RequestMapping(value = "/{instCode}/acn/{acceNumb:.+}/{uuid}", method = { RequestMethod.GET })
public void getImage(final HttpServletRequest request, final HttpServletResponse response, @PathVariable("instCode") final String instCode,
@PathVariable("acceNumb") final String acceNumb, @PathVariable("uuid") final UUID uuid) throws IOException, NonUniqueAccessionException {
public void getImage(final HttpServletRequest request, final HttpServletResponse response, @PathVariable("instCode") final String instCode, @PathVariable("acceNumb") final String acceNumb,
@PathVariable("uuid") final UUID uuid) throws IOException, NonUniqueAccessionException {
final FaoInstitute institute = this.instituteService.findInstitute(instCode);
final Accession accession = this.genesysService.getAccession(instCode, acceNumb);
......@@ -228,8 +228,40 @@ public class InstituteGalleriesController extends RestController {
}
/**
* Add or update image bytes. Content-Type is extracted from request
* headers, the request body represents the bytes.
* Delete image from accession gallery
*
* @throws IOException
* @throws NonUniqueAccessionException
*/
@RequestMapping(value = "/{instCode}/acn/{acceNumb:.+}/{uuid}", method = { RequestMethod.DELETE })
public void deleteImage(final HttpServletRequest request, final HttpServletResponse response, @PathVariable("instCode") final String instCode, @PathVariable("acceNumb") final String acceNumb,
@PathVariable("uuid") final UUID uuid) throws IOException, NonUniqueAccessionException {
final FaoInstitute institute = this.instituteService.findInstitute(instCode);
final Accession accession = this.genesysService.getAccession(instCode, acceNumb);
if (institute == null || accession == null) {
throw new ResourceNotFoundException();
}
LOG.info("Deleting image from gallery institute=" + institute + " accn=" + accession + " uuid=" + uuid);
try {
final RepositoryImage repositoryImage = this.instituteFilesService.getImage(institute, accession, uuid);
if (repositoryImage == null) {
throw new ResourceNotFoundException("No such thing");
}
this.instituteFilesService.deleteImage(institute, accession, repositoryImage);
} catch (final NoSuchRepositoryFileException e) {
LOG.warn("404 - No such repository file ", e);
throw new ResourceNotFoundException("No such thing");
}
}
/**
* Add or update image bytes. Content-Type is extracted from request headers, the request body represents the bytes.
*
* @param originalFilename
*
......@@ -238,10 +270,9 @@ public class InstituteGalleriesController extends RestController {
* @throws InvalidRepositoryPathException
*/
@RequestMapping(value = "/{instCode}/acn/{acceNumb:.+}/", method = { RequestMethod.PUT, RequestMethod.POST }, consumes = { "image/*" }, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody RepositoryImage addImage(final HttpServletRequest request, final HttpServletResponse response,
@PathVariable("instCode") final String instCode, @PathVariable("acceNumb") final String acceNumb,
@RequestParam(name = "originalFilename", required = true) String originalFilename, HttpEntity<byte[]> requestEntity) throws IOException,
NonUniqueAccessionException, InvalidRepositoryPathException, InvalidRepositoryFileDataException {
public @ResponseBody RepositoryImage addImage(final HttpServletRequest request, final HttpServletResponse response, @PathVariable("instCode") final String instCode,
@PathVariable("acceNumb") final String acceNumb, @RequestParam(name = "originalFilename", required = true) String originalFilename, HttpEntity<byte[]> requestEntity)
throws IOException, NonUniqueAccessionException, InvalidRepositoryPathException, InvalidRepositoryFileDataException {
// originalFilename could not be part of the path (and @PathVariable)
// because the wrong content-negotiating strategy kicked in.
......@@ -261,8 +292,7 @@ public class InstituteGalleriesController extends RestController {
imageGallery = this.instituteFilesService.createImageGallery(institute, accession);
}