
eu.agrosense.server.rest.CropFieldResource Maven / Gradle / Ivy
The newest version!
/**
* Copyright (C) 2008-2013 LimeTri. All rights reserved.
*
* AgroSense is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* There are special exceptions to the terms and conditions of the GPLv3 as it
* is applied to this software, see the FLOSS License Exception
* .
*
* AgroSense is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* AgroSense. If not, see .
*/
package eu.agrosense.server.rest;
import eu.agrosense.api.drmcrop.AbstractRingPropertyType;
import eu.agrosense.api.drmcrop.CodeType;
import eu.agrosense.api.drmcrop.CropClass;
import eu.agrosense.api.drmcrop.CropField;
import eu.agrosense.api.drmcrop.CroppingSequenceEnumeration;
import eu.agrosense.api.drmcrop.DirectPositionListType;
import eu.agrosense.api.drmcrop.DirectPositionType;
import eu.agrosense.api.drmcrop.FieldBorderType;
import eu.agrosense.api.drmcrop.LinearRing;
import eu.agrosense.api.drmcrop.QuantityType;
import eu.agrosense.api.drmcrop.StatusEnumeration;
import eu.agrosense.api.drmcrop.Variety;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.GregorianCalendar;
import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import org.openide.util.Exceptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author Timon Veenstra
*/
@Path("cropfield")
@PermitAll
public class CropFieldResource {
private static final Logger log = LoggerFactory.getLogger(CropFieldResource.class);
@RolesAllowed("user")
@GET
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response cropfieldDetails(@QueryParam("id") String id) {
return Response.ok().entity(getCropField(id)).build();
}
@RolesAllowed("user")
@GET
@Path("{id}")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response cropfield(@PathParam("id") String id, @Context SecurityContext securityContext) {
log.debug("get cropfield with id {}",id);
log.debug("has role user in securityContext: {}",securityContext.isUserInRole("user"));
return Response.ok().entity(getCropField(id)).build();
}
private CropField getCropField(String id) {
try {
GregorianCalendar gcal = new GregorianCalendar();
XMLGregorianCalendar xgcal = DatatypeFactory.newInstance().newXMLGregorianCalendar(gcal);
return new CropField()
.withAbstractFieldID(id)
.withArea(new QuantityType()
.withUom(new CodeType()
.withCode("ha"))
.withValue(new BigDecimal(22.8d)))
.withBeginDate(xgcal)
.withBorder(new FieldBorderType()
.withExterior(new AbstractRingPropertyType()
.withAbstractRing(new LinearRing()
.withPosList(new DirectPositionListType()
.withValue(
53.192147, 6.803992,
53.188175, 6.812940,
53.185796, 6.811546,
53.185024, 6.810344,
53.189447, 6.800666,
53.192147, 6.803992
)))))
.withCentreOfGravity(new DirectPositionType().withSrsName("EPSG:4326"))
.withCountry(new CodeType().withCode("NL"))
.withCropClass(new CropClass().withCropClassDesignator("potato"))
.withCropProductionPeriodCode(new CodeType().withCode("CropProductionPeriodCode"))
.withCropProductionSequence(CroppingSequenceEnumeration.MAIN)
.withCropYear(new BigInteger("2014"))
.withEndDate(xgcal)
.withFieldDesignator(id)
// .withOperation(null)
.withOrganic(Boolean.FALSE)
// .withProductionTypeCode(
// new CodeType()
// .withCode("[TODO]MyProductionType")
// .withCodeListCode(
// new CodeListType()
// .withCodeListURI("[TODO]ProductionTypeCodeListUri")))
.withStatus(StatusEnumeration.PLANNED)
.withThirdPartyFieldGUID(null)
.withVariety(new Variety()
.withVarietyDesignator("Starga"))
.withXYCoordinate(new DirectPositionType()
.withSrsName("EPSG:4326").withSrsDimension(new BigInteger("1234")));
} catch (DatatypeConfigurationException ex) {
Exceptions.printStackTrace(ex);
throw new RuntimeException(ex);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy