Commit 6b17b3ee authored by Matija Obreza's avatar Matija Obreza

RepositoryFile#uuid must be available

parent 7c77564e
......@@ -33,12 +33,11 @@ import java.util.Properties;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import javax.activation.FileTypeMap;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
......@@ -76,7 +75,7 @@ public class GenesysClient {
private static final String SCOPE = "read,write";
/** The mapper. */
private static ObjectMapper objectMapper = new ObjectMapper();
private static ObjectMapper objectMapper;
/** The service. */
private OAuthService service;
......@@ -102,11 +101,14 @@ public class GenesysClient {
/** UTF8 charset */
private static Charset CHARSET_UTF8 = Charset.forName("UTF8");
static {
objectMapper = new ObjectMapper();
objectMapper.configure(SerializationFeature.WRITE_ENUMS_USING_TO_STRING, true);
objectMapper.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false);
objectMapper.setSerializationInclusion(Include.NON_NULL);
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
}
/**
......@@ -1119,21 +1121,7 @@ public class GenesysClient {
return objectMapper.readValue(json, new TypeReference<List<UUID>>() {
});
}
/**
* Add image to accession
*
* @param instCode institute code (MCPD INSTCODE)
* @param acceNumb accession number (MCPD ACCENUMB)
* @param file image to upload
* @throws IOException if file cannot be read
* @throws GenesysApiException
*/
public RepositoryImage uploadImage(final String instCode, final String acceNumb, final File file) throws GenesysApiException, IOException {
final String contentType = FileTypeMap.getDefaultFileTypeMap().getContentType(file.getName());
return uploadImage(instCode, acceNumb, file, contentType);
}
/**
* Add image to accession
*
......@@ -1148,10 +1136,13 @@ public class GenesysClient {
if (StringUtils.isBlank(contentType))
throw new GenesysApiException("Content-Type must be provided for the file " + file.getAbsolutePath());
_log.debug("Image content type: " + contentType);
// PUT file on server
final String json = query(Verb.PUT, String.format("/img/%1$s/acn/%2$s", instCode, acceNumb), Collections.singletonMap("originalFilename", file.getName()), contentType,
final String json = query(Verb.PUT, String.format("/img/%1$s/acn/%2$s/", instCode, acceNumb), Collections.singletonMap("originalFilename", file.getName()), contentType,
FileUtils.readFileToByteArray(file));
System.err.println(json);
// Deserialize JSON
return objectMapper.readValue(json, RepositoryImage.class);
}
......
......@@ -18,6 +18,7 @@ package org.genesys2.client.oauth.api.images;
import java.io.Serializable;
import java.util.Date;
import java.util.UUID;
/**
* Data only. Copied from genesys-file-repository.
......@@ -25,6 +26,7 @@ import java.util.Date;
public class RepositoryFile implements Serializable {
private static final long serialVersionUID = -6507809172296678924L;
private UUID uuid;
private String title;
private String subject;
private String description;
......@@ -40,9 +42,16 @@ public class RepositoryFile implements Serializable {
private Date modified;
private String identifier;
private String originalFilename;
private String contentType;
public UUID getUuid() {
return uuid;
}
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
public String getAccessRights() {
return accessRights;
}
......
/*
* Copyright 2016 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.geneys2.client.oauth;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.genesys2.client.oauth.api.images.RepositoryImage;
import org.junit.Test;
public class AccessionImagesTest {
/** The mapper. */
private static ObjectMapper objectMapper;
static {
objectMapper = new ObjectMapper();
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
}
@Test
public void testJson1() throws JsonParseException, JsonMappingException, IOException {
String json = "{\"id\":123451,\"uuid\":\"94401ab9-c528-458c-a224-c8ca5bd41790\",\"path\":\"/accessions/INS001/acn/ACC001/\",\"originalFilename\":\"someimage.png\",\"extension\":\".png\",\"title\":null,\"subject\":null,\"description\":null,\"creator\":null,\"created\":null,\"rightsHolder\":null,\"accessRights\":null,\"license\":null,\"contentType\":\"image/png\",\"extent\":null,\"bibliographicCitation\":null,\"createdDate\":1471436704417,\"lastModifiedDate\":1471436704417,\"originalUrl\":null,\"dateRetrieved\":null,\"sha1Sum\":\"f4b0ce7212bd3ff595a37927bd50b05922f1dd16\",\"md5Sum\":\"315cff83297068a4b406e08f8eaf3d3c\",\"width\":842,\"height\":355,\"orientation\":\"LANDSCAPE\",\"format\":\"image/png\",\"identifier\":\"urn:uuid:94404ab9-c528-458c-a224-c8ca5bd41790\",\"dateSubmitted\":1471436704417,\"modified\":1471436704417,\"filename\":\"94404ab9-c528-458c-a224-c8ca5bd41790.png\",\"url\":\"/accessions/INS000/acn/ACC0000/94401ab9-c528-458c-a224-c8ca5bd41790.png\"}";
objectMapper.readValue(json, RepositoryImage.class);
}
}
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