ItEr40S20CUImportacionRecursosProductivosItEr39S23: REST service for importing resources exported remotely.
REST service for importing resources has been exported remotely. A script and a sample file with resources is also provided. Complex validations are not implemented yet.
This commit is contained in:
parent
6f2754ae56
commit
a01c1fa5b3
6 changed files with 70 additions and 0 deletions
|
|
@ -25,12 +25,14 @@ import java.util.List;
|
|||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElements;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
* DTO for a list of <code>Resource</code> entities.
|
||||
*
|
||||
* @author Fernando Bellas Permuy <fbellas@udc.es>
|
||||
*/
|
||||
@XmlRootElement(name="resource-list")
|
||||
public class ResourceListDTO {
|
||||
|
||||
@XmlElements({
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ package org.navalplanner.ws.resources.impl;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
|
|
@ -38,6 +40,7 @@ import org.navalplanner.ws.resources.api.ResourceDTO;
|
|||
import org.navalplanner.ws.resources.api.ResourceListDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* REST-based implementation of <code>IResourceService</code>.
|
||||
|
|
@ -53,6 +56,9 @@ public class ResourceServiceREST implements IResourceService {
|
|||
private IResourceDAO resourceDAO;
|
||||
|
||||
@Override
|
||||
@POST
|
||||
@Consumes("application/xml")
|
||||
@Transactional
|
||||
public InstanceConstraintViolationsListDTO addResources(
|
||||
ResourceListDTO resources) {
|
||||
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@
|
|||
<jaxrs:serviceBeans>
|
||||
<ref bean="criterionServiceREST"/>
|
||||
<ref bean="orderElementServiceREST"/>
|
||||
<ref bean="resourceServiceREST"/>
|
||||
</jaxrs:serviceBeans>
|
||||
<jaxrs:providers>
|
||||
<ref bean="runtimeExceptionMapper" />
|
||||
|
|
|
|||
|
|
@ -20,9 +20,20 @@
|
|||
|
||||
- export-criterion-types.sh (authenticate with wsreader/wsreader)
|
||||
|
||||
* Import resources:
|
||||
|
||||
- import-resources.sh resources-sample.xml
|
||||
(authenticate with wswriter/wswriter)
|
||||
|
||||
- Check the returned errors are consistent with the comments in
|
||||
resources-sample.xml.
|
||||
|
||||
+ When working with the online demo:
|
||||
|
||||
* import-criterions-types.sh --prod criterion-types-sample.xml
|
||||
(authenticate with wswriter/wswriter)
|
||||
|
||||
* export-criterion-types.sh --prod (authenticate with wsreader/wsreader)
|
||||
|
||||
* import-resources.sh --prod resources-sample.xml
|
||||
(authenticate with wswriter/wswriter)
|
||||
|
|
|
|||
33
scripts/rest-clients/import-resources.sh
Executable file
33
scripts/rest-clients/import-resources.sh
Executable file
|
|
@ -0,0 +1,33 @@
|
|||
#!/bin/sh
|
||||
|
||||
. ./rest-common-env.sh
|
||||
|
||||
printf "Login name: "
|
||||
read loginName
|
||||
printf "Password: "
|
||||
read password
|
||||
|
||||
baseServiceURL=$DEVELOPMENT_BASE_SERVICE_URL
|
||||
certificate=$DEVELOPMENT_CERTIFICATE
|
||||
|
||||
for i in "$@"
|
||||
do
|
||||
if [ "$i" = "--prod" ]; then
|
||||
baseServiceURL=$PRODUCTION_BASE_SERVICE_URL
|
||||
certificate=$PRODUCTION_CERTIFICATE
|
||||
else
|
||||
file=$i
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$file" = "" ]; then
|
||||
printf "Missing file\n" 1>&2
|
||||
exit -1
|
||||
fi
|
||||
|
||||
authorization=`./base64.sh $loginName:$password`
|
||||
|
||||
curl -sv -X POST $certificate -d @$file \
|
||||
--header "Content-type: application/xml" \
|
||||
--header "Authorization: Basic $authorization" \
|
||||
$baseServiceURL/resources | tidy -xml -i -q -utf8
|
||||
17
scripts/rest-clients/resources-sample.xml
Normal file
17
scripts/rest-clients/resources-sample.xml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
|
||||
<resource-list xmlns="http://rest.ws.navalplanner.org">
|
||||
|
||||
<!-- *** Machines *** -->
|
||||
<!-- OK -->
|
||||
<machine code="m1" name="m1-name" description="m1-desc"/>
|
||||
<!-- Missing code and name (description is optional). -->
|
||||
<machine code="" description=""/>
|
||||
|
||||
<!-- *** Workers *** -->
|
||||
<!-- OK -->
|
||||
<worker first-name="w1-firstName" surname="w1-surname" nif="w1-nif"/>
|
||||
<!-- Missing first name, surname, and nif. -->
|
||||
<worker first-name="" surname="" nif=""/>
|
||||
|
||||
</resource-list>
|
||||
Loading…
Add table
Reference in a new issue