Exception type web services.

* Added new field to export service.
* Implemented import service and added example.

FEA: ItEr61S06ExceptionTypeEntity
This commit is contained in:
Manuel Rego Casasnovas 2010-10-13 16:32:17 +02:00
parent 6b07e6c7f6
commit f00ba4f3ce
7 changed files with 95 additions and 5 deletions

View file

@ -66,6 +66,14 @@ public class CalendarExceptionType extends IntegrationEntity {
code);
}
public static CalendarExceptionType create(String code, String name,
String color, Boolean notAssignable, EffortDuration duration) {
CalendarExceptionType calendarExceptionType = new CalendarExceptionType(
name, color, notAssignable);
calendarExceptionType.setDuration(duration);
return create(calendarExceptionType, code);
}
/**
* Constructor for hibernate. Do not use!
*/

View file

@ -43,20 +43,24 @@ public class CalendarExceptionTypeDTO extends IntegrationEntityDTO {
@XmlAttribute(name = "over-assignable")
public boolean overAssignable;
@XmlAttribute
public int duration;
public CalendarExceptionTypeDTO() {
}
public CalendarExceptionTypeDTO(String code, String name, String color,
boolean overAssignable) {
boolean overAssignable, int duration) {
super(code);
this.name = name;
this.color = color;
this.overAssignable = overAssignable;
this.duration = duration;
}
public CalendarExceptionTypeDTO(String name, String color,
boolean overAssignable) {
this(generateCode(), name, color, overAssignable);
boolean overAssignable, int duration) {
this(generateCode(), name, color, overAssignable, duration);
}
@Override

View file

@ -21,6 +21,7 @@
package org.navalplanner.ws.calendarexceptiontypes.api;
import org.navalplanner.business.calendars.entities.CalendarExceptionType;
import org.navalplanner.ws.common.api.InstanceConstraintViolationsListDTO;
/**
* Service for managing {@link CalendarExceptionType} entities.
@ -31,4 +32,7 @@ public interface ICalendarExceptionTypeService {
CalendarExceptionTypeListDTO getCalendarExceptionType();
InstanceConstraintViolationsListDTO addCalendarExceptionTypes(
CalendarExceptionTypeListDTO calendarExceptionTypeListDTO);
}

View file

@ -21,6 +21,7 @@
package org.navalplanner.ws.calendarexceptiontypes.impl;
import org.navalplanner.business.calendars.entities.CalendarExceptionType;
import org.navalplanner.business.workingday.EffortDuration;
import org.navalplanner.ws.calendarexceptiontypes.api.CalendarExceptionTypeDTO;
/**
@ -36,9 +37,27 @@ public final class CalendarExceptionTypeConverter {
public final static CalendarExceptionTypeDTO toDTO(
CalendarExceptionType calendarExceptionType) {
EffortDuration duration = calendarExceptionType.getDuration();
int seconds = (duration != null) ? duration.getSeconds() : 0;
return new CalendarExceptionTypeDTO(calendarExceptionType.getCode(),
calendarExceptionType.getName(), calendarExceptionType
.getColor(), calendarExceptionType.isOverAssignable());
.getColor(), calendarExceptionType.isOverAssignable(),
seconds);
}
public final static CalendarExceptionType toEntity(
CalendarExceptionTypeDTO entityDTO) {
return CalendarExceptionType.create(entityDTO.code, entityDTO.name,
entityDTO.color, entityDTO.overAssignable, EffortDuration
.seconds(entityDTO.duration));
}
public static void updateCalendarExceptionType(
CalendarExceptionType entity, CalendarExceptionTypeDTO entityDTO) {
entity.setName(entityDTO.name);
entity.setColor(entityDTO.color);
entity.setOverAssignable(entityDTO.overAssignable);
entity.setDuration(EffortDuration.seconds(entityDTO.duration));
}
}

View file

@ -20,7 +20,9 @@
package org.navalplanner.ws.calendarexceptiontypes.impl;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
@ -31,6 +33,7 @@ import org.navalplanner.business.common.exceptions.ValidationException;
import org.navalplanner.ws.calendarexceptiontypes.api.CalendarExceptionTypeDTO;
import org.navalplanner.ws.calendarexceptiontypes.api.CalendarExceptionTypeListDTO;
import org.navalplanner.ws.calendarexceptiontypes.api.ICalendarExceptionTypeService;
import org.navalplanner.ws.common.api.InstanceConstraintViolationsListDTO;
import org.navalplanner.ws.common.impl.GenericRESTService;
import org.navalplanner.ws.common.impl.RecoverableErrorException;
import org.springframework.beans.factory.annotation.Autowired;
@ -66,13 +69,15 @@ public class CalendarExceptionTypeServiceREST extends
@Override
protected CalendarExceptionType toEntity(CalendarExceptionTypeDTO entityDTO)
throws ValidationException, RecoverableErrorException {
return null;
return CalendarExceptionTypeConverter.toEntity(entityDTO);
}
@Override
protected void updateEntity(CalendarExceptionType entity,
CalendarExceptionTypeDTO entityDTO) throws ValidationException,
RecoverableErrorException {
CalendarExceptionTypeConverter.updateCalendarExceptionType(entity,
entityDTO);
}
@Override
@ -82,4 +87,12 @@ public class CalendarExceptionTypeServiceREST extends
return new CalendarExceptionTypeListDTO(findAll());
}
@Override
@POST
@Consumes("application/xml")
public InstanceConstraintViolationsListDTO addCalendarExceptionTypes(
CalendarExceptionTypeListDTO calendarExceptionTypeListDTO) {
return save(calendarExceptionTypeListDTO.calendarExceptionTypes);
}
}

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<calendar-exception-type-list xmlns="http://rest.ws.navalplanner.org">
<calendar-exception-type code="HALF_DAY" name="Half day"
color="green" duration="14400" over-assignable="true" />
<calendar-exception-type code="AVAILABILITY" name="Availability"
color="blue" duration="0" over-assignable="true" />
</calendar-exception-type-list>

View 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/calendarexceptiontypes | tidy -xml -i -q -utf8