Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys CLI
Commits
cf903ec2
Commit
cf903ec2
authored
Aug 17, 2016
by
Matija Obreza
Browse files
Accession Gallery commands
parent
87e108c2
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys2/client/component/JsonPrinter.java
View file @
cf903ec2
...
...
@@ -17,16 +17,17 @@
package
org.genesys2.client.component
;
import
java.io.IOException
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
java.io.Serializable
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectWriter
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
@Component
public
class
JsonPrinter
implements
InitializingBean
{
@Autowired
...
...
@@ -47,4 +48,8 @@ public class JsonPrinter implements InitializingBean {
public
String
prettyPrint
(
JsonNode
node
)
throws
JsonProcessingException
{
return
printer
.
writeValueAsString
(
node
);
}
public
String
prettyPrint
(
Serializable
serializable
)
throws
JsonProcessingException
{
return
printer
.
writeValueAsString
(
serializable
);
}
}
src/main/java/org/genesys2/client/shell/AccessionCommands.java
View file @
cf903ec2
...
...
@@ -18,6 +18,10 @@ package org.genesys2.client.shell;
import
java.io.IOException
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
org.genesys2.client.component.JsonEditor
;
import
org.genesys2.client.component.JsonPrinter
;
import
org.genesys2.client.oauth.GenesysApiException
;
...
...
@@ -25,7 +29,6 @@ import org.genesys2.client.oauth.GenesysClient;
import
org.genesys2.client.oauth.OAuthAuthenticationException
;
import
org.genesys2.client.oauth.PleaseRetryException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.shell.core.CommandMarker
;
import
org.springframework.shell.core.ExecutionProcessor
;
import
org.springframework.shell.core.annotation.CliAvailabilityIndicator
;
import
org.springframework.shell.core.annotation.CliCommand
;
...
...
@@ -33,10 +36,6 @@ import org.springframework.shell.core.annotation.CliOption;
import
org.springframework.shell.event.ParseResult
;
import
org.springframework.stereotype.Component
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
jline.internal.Log
;
@Component
...
...
src/main/java/org/genesys2/client/shell/AccessionGalleryCommands.java
0 → 100644
View file @
cf903ec2
/**
* Copyright 2014 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.genesys2.client.shell
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.UUID
;
import
com.fasterxml.jackson.core.JsonParseException
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.JsonMappingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
org.genesys2.client.component.JsonEditor
;
import
org.genesys2.client.component.JsonPrinter
;
import
org.genesys2.client.oauth.GenesysApiException
;
import
org.genesys2.client.oauth.GenesysClient
;
import
org.genesys2.client.oauth.OAuthAuthenticationException
;
import
org.genesys2.client.oauth.PleaseRetryException
;
import
org.genesys2.client.oauth.api.images.RepositoryImage
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.shell.core.CommandMarker
;
import
org.springframework.shell.core.annotation.CliAvailabilityIndicator
;
import
org.springframework.shell.core.annotation.CliCommand
;
import
org.springframework.shell.core.annotation.CliOption
;
import
org.springframework.stereotype.Component
;
/**
* Accession images
*/
@Component
public
class
AccessionGalleryCommands
implements
CommandMarker
{
@Autowired
private
GenesysClient
genesysClient
;
@Autowired
private
ObjectMapper
mapper
;
@Autowired
private
JsonPrinter
printer
;
@Autowired
private
JsonEditor
editor
;
private
ObjectNode
currentCrop
=
null
;
private
ArrayNode
currentCropRules
=
null
;
private
String
instCode
;
private
String
acceNumb
;
private
UUID
uuid
;
private
RepositoryImage
imageData
;
@CliAvailabilityIndicator
({
"gallery list"
})
public
boolean
isSimpleAvailable
()
{
return
true
;
}
@CliCommand
(
value
=
"gallery list"
,
help
=
"List galleries"
)
public
String
list
(
@CliOption
(
key
=
{
""
,
"instCode"
},
mandatory
=
true
)
String
instCode
,
@CliOption
(
key
=
{
""
,
"page"
},
unspecifiedDefaultValue
=
"1"
,
mandatory
=
false
,
help
=
"Page number"
)
int
page
)
throws
JsonProcessingException
,
OAuthAuthenticationException
,
PleaseRetryException
,
IOException
,
GenesysApiException
{
return
printer
.
prettyPrint
(
genesysClient
.
listGalleries
(
instCode
,
page
));
}
@CliCommand
(
value
=
"gallery upload"
,
help
=
"Upload image to accession gallery"
)
public
String
upload
(
@CliOption
(
key
=
{
""
,
"instCode"
},
mandatory
=
true
,
help
=
"WIEWS Institute code (INSTCODE)"
)
String
instCode
,
@CliOption
(
key
=
{
""
,
"acceNumb"
},
mandatory
=
true
,
help
=
"Accession number (ACCENUMB)"
)
String
acceNumb
,
@CliOption
(
key
=
{
""
,
"contentType"
},
mandatory
=
false
,
unspecifiedDefaultValue
=
"image/jpeg"
,
help
=
"Image MIME type"
)
String
contentType
,
@CliOption
(
key
=
{
""
,
"file"
},
mandatory
=
true
,
help
=
"Image to upload"
)
File
file
)
throws
JsonProcessingException
,
OAuthAuthenticationException
,
PleaseRetryException
,
IOException
,
GenesysApiException
,
JsonParseException
,
JsonMappingException
{
this
.
imageData
=
genesysClient
.
uploadImage
(
instCode
,
acceNumb
,
file
,
contentType
);
this
.
instCode
=
instCode
;
this
.
acceNumb
=
acceNumb
;
this
.
uuid
=
imageData
.
getUuid
();
return
printer
.
prettyPrint
(
this
.
imageData
);
}
@CliCommand
(
value
=
"gallery delete"
,
help
=
"Delete image from accession gallery"
)
public
void
delete
(
@CliOption
(
key
=
{
""
,
"instCode"
},
mandatory
=
true
,
help
=
"WIEWS Institute code (INSTCODE)"
)
String
instCode
,
@CliOption
(
key
=
{
""
,
"acceNumb"
},
mandatory
=
true
,
help
=
"Accession number (ACCENUMB)"
)
String
acceNumb
,
@CliOption
(
key
=
{
""
,
"uuid"
},
mandatory
=
true
,
help
=
"Image UUID"
)
String
uuid
)
throws
OAuthAuthenticationException
,
PleaseRetryException
,
GenesysApiException
{
genesysClient
.
deleteImage
(
instCode
,
acceNumb
,
UUID
.
fromString
(
uuid
));
}
@CliCommand
(
value
=
"gallery metadata"
,
help
=
"Get image metadata from accession gallery"
)
public
String
readMetadata
(
@CliOption
(
key
=
{
""
,
"instCode"
},
mandatory
=
true
,
help
=
"WIEWS Institute code (INSTCODE)"
)
String
instCode
,
@CliOption
(
key
=
{
""
,
"acceNumb"
},
mandatory
=
true
,
help
=
"Accession number (ACCENUMB)"
)
String
acceNumb
,
@CliOption
(
key
=
{
""
,
"uuid"
},
mandatory
=
true
,
help
=
"Image UUID"
)
String
uuid
)
throws
OAuthAuthenticationException
,
PleaseRetryException
,
GenesysApiException
,
IOException
{
this
.
imageData
=
genesysClient
.
getImageMetadata
(
instCode
,
acceNumb
,
UUID
.
fromString
(
uuid
));
this
.
instCode
=
instCode
;
this
.
acceNumb
=
acceNumb
;
this
.
uuid
=
imageData
.
getUuid
();
return
printer
.
prettyPrint
(
this
.
imageData
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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