Commit 91536f69 authored by Kristjan Kruus's avatar Kristjan Kruus Committed by GitHub

Merge pull request #34 from e-gov/develop

Develop
parents 587f600f 521bc8a0
Pipeline #41 failed with stages
......@@ -5,7 +5,7 @@
<groupId>ee.eesti.riha</groupId>
<artifactId>rest</artifactId>
<version>0.17.0</version>
<version>0.17.1</version>
<packaging>war</packaging>
......@@ -658,4 +658,4 @@
</project>
\ No newline at end of file
</project>
......@@ -76,6 +76,34 @@ public class FileResourceLogic {
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 {
......
......@@ -63,4 +63,19 @@ public interface FileService {
@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);
}
......@@ -11,8 +11,8 @@ import ee.eesti.riha.rest.logic.util.JsonHelper;
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.beans.factory.annotation.Autowired;
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 class FileServiceImpl implements FileService {
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();
}
}
Markdown is supported
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