Commit 7c3a0626 authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch 'repository-upload-with-metadata' into 'master'

Repository controller accepts metadata as string

See merge request !138
parents 1a9effbd 39f1ae61
......@@ -20,6 +20,7 @@ import java.util.UUID;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.genesys.catalog.exceptions.InvalidApiUsageException;
import org.genesys.catalog.exceptions.NotFoundElement;
import org.genesys.filerepository.InvalidRepositoryFileDataException;
......@@ -41,6 +42,8 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* @author Matija Obreza
*/
......@@ -52,15 +55,19 @@ public class RepositoryController {
protected static final String API_BASE = "/api/v0/repository";
private static final Logger LOG = LoggerFactory.getLogger(RepositoryController.class);
private ObjectMapper objectMapper = new ObjectMapper();
@Autowired
protected RepositoryService repositoryService;
@PostMapping(value = "/add")
public RepositoryFile addFile(@RequestParam("file") final MultipartFile inputFile, @RequestParam("metadata") RepositoryFile metadata) throws NotFoundElement,
public RepositoryFile addFile(@RequestParam("file") final MultipartFile inputFile, @RequestParam("metadata") String metadataJson) throws NotFoundElement,
InvalidRepositoryFileDataException, InvalidRepositoryPathException, IOException {
LOG.info("Uploading {} to repository", inputFile.getOriginalFilename());
return repositoryService.addFile(metadata.getPath(), inputFile.getOriginalFilename(), inputFile.getContentType(), inputFile.getBytes(), metadata);
RepositoryFile metadata = objectMapper.readValue(metadataJson, RepositoryFile.class);
String fileName = StringUtils.defaultString(metadata.getOriginalFilename(), inputFile.getOriginalFilename());
LOG.info("Uploading {} to repository", fileName);
return repositoryService.addFile(metadata.getPath(), fileName, inputFile.getContentType(), inputFile.getBytes(), metadata);
}
@GetMapping(value = "/{fileUuid}")
......
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