Skip to content

Commit

Permalink
Merge pull request #34 from e-gov/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
KristjanKruusRIA authored Jun 4, 2019
2 parents 587f600 + 521bc8a commit 91536f6
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -658,4 +658,4 @@



</project>
</project>
28 changes: 28 additions & 0 deletions src/main/java/ee/eesti/riha/rest/logic/FileResourceLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/ee/eesti/riha/rest/service/FileService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
35 changes: 23 additions & 12 deletions src/main/java/ee/eesti/riha/rest/service/impl/FileServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
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;
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;
Expand All @@ -43,9 +43,9 @@ public class FileServiceImpl implements FileService {
@Autowired
private FileResourceLogic fileResourceLogic;

@Autowired
private PagedRequestArgumentResolver pagedRequestArgumentResolver;

@Autowired
private PagedRequestArgumentResolver pagedRequestArgumentResolver;

/*
* (non-Javadoc)
*
Expand Down Expand Up @@ -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();
}
}

0 comments on commit 91536f6

Please sign in to comment.