Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
Java Client API
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
3
Issues
3
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Genesys PGR
Java Client API
Commits
6b17b3ee
Commit
6b17b3ee
authored
Aug 17, 2016
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RepositoryFile#uuid must be available
parent
7c77564e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
20 deletions
+64
-20
src/main/java/org/genesys2/client/oauth/GenesysClient.java
src/main/java/org/genesys2/client/oauth/GenesysClient.java
+10
-19
src/main/java/org/genesys2/client/oauth/api/images/RepositoryFile.java
.../org/genesys2/client/oauth/api/images/RepositoryFile.java
+10
-1
src/test/java/org/geneys2/client/oauth/AccessionImagesTest.java
...st/java/org/geneys2/client/oauth/AccessionImagesTest.java
+44
-0
No files found.
src/main/java/org/genesys2/client/oauth/GenesysClient.java
View file @
6b17b3ee
...
...
@@ -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
);
}
...
...
src/main/java/org/genesys2/client/oauth/api/images/RepositoryFile.java
View file @
6b17b3ee
...
...
@@ -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
;
}
...
...
src/test/java/org/geneys2/client/oauth/AccessionImagesTest.java
0 → 100644
View file @
6b17b3ee
/*
* 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
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment