From 8b0694b012ce3732690ef43929ccd89141f0b131 Mon Sep 17 00:00:00 2001 From: Vadim Nesmashnov Date: Wed, 29 May 2019 16:28:02 +0300 Subject: [PATCH 1/2] RIHAKB-814, File links for user of standard solutions don't work --- .../riha/rest/logic/FileResourceLogic.java | 28 +++++++++++++++ .../eesti/riha/rest/service/FileService.java | 15 ++++++++ .../rest/service/impl/FileServiceImpl.java | 35 ++++++++++++------- 3 files changed, 66 insertions(+), 12 deletions(-) diff --git a/src/main/java/ee/eesti/riha/rest/logic/FileResourceLogic.java b/src/main/java/ee/eesti/riha/rest/logic/FileResourceLogic.java index 6c578e5..551abb8 100644 --- a/src/main/java/ee/eesti/riha/rest/logic/FileResourceLogic.java +++ b/src/main/java/ee/eesti/riha/rest/logic/FileResourceLogic.java @@ -76,6 +76,34 @@ public UUID createFileResource(InputStream inputStream, UUID infoSystemUuid, Str return uuid; } + /** + * Creates a copy of {@link FileResource} with new info system UUID + * + * @param existingFileUuid UUID of existing file resource + * @param existingInfoSystemUuid existing info system UUID + * @param newInfoSystemUuid new info system UUID + * @return UUID of created file resource + */ + @Transactional + public UUID createFileResourceFromExisting(UUID existingFileUuid, UUID existingInfoSystemUuid, UUID newInfoSystemUuid) { + FileResource existingFileResource = fileResourceDAO.get(existingFileUuid, existingInfoSystemUuid); + + if (existingFileResource == null) { + throw new IllegalStateException("FileResource with uuid " + existingFileUuid + " and info system uuid " + existingInfoSystemUuid + " is not found"); + } + + FileResource newFileResource = new FileResource(); + newFileResource.setInfoSystemUuid(newInfoSystemUuid); + newFileResource.setName(existingFileResource.getName()); + newFileResource.setContentType(existingFileResource.getContentType()); + newFileResource.setLargeObject(existingFileResource.getLargeObject()); + + UUID uuid = fileResourceDAO.create(newFileResource); + logger.info("Created file resource '{}'", uuid); + + return uuid; + } + @Transactional public void indexFileResource(UUID uuid) { try { diff --git a/src/main/java/ee/eesti/riha/rest/service/FileService.java b/src/main/java/ee/eesti/riha/rest/service/FileService.java index c0142df..195805a 100644 --- a/src/main/java/ee/eesti/riha/rest/service/FileService.java +++ b/src/main/java/ee/eesti/riha/rest/service/FileService.java @@ -63,4 +63,19 @@ Response download(@PathParam("fileUuid") String fileUuidStr, @Produces(MediaType.APPLICATION_JSON + "; charset=UTF-8") Response list(@Context UriInfo uriInfo); + /** + * Creates new file resource by copying existing one with new info system UUID + * + * @param existingFileUuid file uuid to copy from + * @param existingInfoSystemUuid info system uuid to copy from + * @param newInfoSystemUuid new info system uuid + * @return uuid of created file resource + */ + + @Path("/api/file/createFromExisting") + @POST + Response createFileResourceFromExisting( + @QueryParam(value = "existingFileUuid") String existingFileUuid, + @QueryParam(value = "existingInfoSystemUuid") String existingInfoSystemUuid, + @QueryParam(value = "newInfoSystemUuid") String newInfoSystemUuid); } diff --git a/src/main/java/ee/eesti/riha/rest/service/impl/FileServiceImpl.java b/src/main/java/ee/eesti/riha/rest/service/impl/FileServiceImpl.java index 7768ee9..36a81c6 100644 --- a/src/main/java/ee/eesti/riha/rest/service/impl/FileServiceImpl.java +++ b/src/main/java/ee/eesti/riha/rest/service/impl/FileServiceImpl.java @@ -11,8 +11,8 @@ import ee.eesti.riha.rest.model.Document; import ee.eesti.riha.rest.model.FileResource; import ee.eesti.riha.rest.service.FileService; -import ee.eesti.riha.rest.util.PagedRequest; -import ee.eesti.riha.rest.util.PagedRequestArgumentResolver; +import ee.eesti.riha.rest.util.PagedRequest; +import ee.eesti.riha.rest.util.PagedRequestArgumentResolver; import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -20,7 +20,7 @@ import org.springframework.util.StringUtils; import javax.activation.DataHandler; -import javax.ws.rs.core.*; +import javax.ws.rs.core.*; import javax.ws.rs.core.Response.Status; import java.io.File; import java.io.IOException; @@ -43,9 +43,9 @@ public class FileServiceImpl implements FileService { @Autowired private FileResourceLogic fileResourceLogic; - @Autowired - private PagedRequestArgumentResolver pagedRequestArgumentResolver; - + @Autowired + private PagedRequestArgumentResolver pagedRequestArgumentResolver; + /* * (non-Javadoc) * @@ -140,10 +140,21 @@ public void write(final OutputStream output) throws IOException { return response.entity(streamingOutput).build(); } - @Override - public Response list(UriInfo uriInfo) { - PagedRequest request = pagedRequestArgumentResolver.resolve(uriInfo.getQueryParameters()); - return Response.ok(fileResourceLogic.list(request)).build(); - } - + @Override + public Response list(UriInfo uriInfo) { + PagedRequest request = pagedRequestArgumentResolver.resolve(uriInfo.getQueryParameters()); + return Response.ok(fileResourceLogic.list(request)).build(); + } + + @Override + public Response createFileResourceFromExisting(String existingFileUuid, String existingInfoSystemUuidStr, String newInfoSystemUuidStr) { + final UUID fileResourceUuid = UUID.fromString(existingFileUuid); + final UUID existingInfoSystemUuid = UUID.fromString(existingInfoSystemUuidStr); + final UUID newInfoSystemUuid = UUID.fromString(newInfoSystemUuidStr); + + UUID uuid = fileResourceLogic.createFileResourceFromExisting( + fileResourceUuid, existingInfoSystemUuid, newInfoSystemUuid); + + return Response.ok(uuid.toString()).build(); + } } From 521bc8a0bf8a04de423f5fd82e10902b74864e5c Mon Sep 17 00:00:00 2001 From: Kristjan Kruus Date: Fri, 31 May 2019 13:19:50 +0300 Subject: [PATCH 2/2] Update pom.xml --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 56e3555..9efc1f1 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ ee.eesti.riha rest - 0.17.0 + 0.17.1 war @@ -658,4 +658,4 @@ - \ No newline at end of file +