Search in sources :

Example 1 with Process

use of org.n52.shetland.inspire.ompr.Process in project series-rest-api by 52North.

the class BaseController method writeExceptionResponse.

private void writeExceptionResponse(WebException e, HttpServletResponse response, HttpStatus status) {
    final String logMessage = "An exception occured.";
    if (status == HttpStatus.INTERNAL_SERVER_ERROR) {
        LOGGER.error(logMessage, e);
    } else {
        LOGGER.debug(logMessage, e);
    }
    // TODO consider using a 'suppress_response_codes=true' parameter and always return 200 OK
    response.setStatus(status.value());
    response.setContentType(MimeType.APPLICATION_JSON.getMimeType());
    ObjectMapper objectMapper = createObjectMapper();
    ObjectWriter writer = objectMapper.writerFor(ExceptionResponse.class);
    ExceptionResponse exceptionResponse = ExceptionResponse.createExceptionResponse(e, status);
    try (OutputStream outputStream = response.getOutputStream()) {
        writer.writeValue(outputStream, exceptionResponse);
    } catch (IOException ioe) {
        LOGGER.error("Could not process error message.", ioe);
    }
}
Also used : ExceptionResponse(org.n52.web.exception.ExceptionResponse) OutputStream(java.io.OutputStream) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with Process

use of org.n52.shetland.inspire.ompr.Process in project arctic-sea by 52North.

the class ProcessDocumentDecoder method decode.

@Override
public Process decode(ProcessDocument pd) throws DecodingException {
    Process process = parseProcessType(pd.getProcess());
    process.setXml(pd.xmlText(getXmlOptions()));
    return process;
}
Also used : Process(org.n52.shetland.inspire.ompr.Process)

Example 3 with Process

use of org.n52.shetland.inspire.ompr.Process in project arctic-sea by 52North.

the class ProcessTypeDecoder method decode.

@Override
public Process decode(ProcessType pt) throws DecodingException {
    Process process = parseProcessType(pt);
    process.setXml(pt.xmlText(getXmlOptions()));
    return process;
}
Also used : Process(org.n52.shetland.inspire.ompr.Process)

Example 4 with Process

use of org.n52.shetland.inspire.ompr.Process in project arctic-sea by 52North.

the class SensorMLEncoderv101 method addAbstractProcessValues.

// TODO refactor/rename
private void addAbstractProcessValues(final AbstractProcessType abstractProcess, final AbstractProcess sosAbstractProcess) throws EncodingException {
    if (sosAbstractProcess.isSetGmlID()) {
        abstractProcess.setId(sosAbstractProcess.getGmlId());
    }
    if (sosAbstractProcess.isSetCapabilities()) {
        final Capabilities[] existing = abstractProcess.getCapabilitiesArray();
        final Set<String> names = Sets.newHashSetWithExpectedSize(existing.length);
        for (final Capabilities element : existing) {
            if (element.getName() != null) {
                names.add(element.getName());
            }
        }
        for (final SmlCapabilities sosCapability : sosAbstractProcess.getCapabilities()) {
            final Capabilities c = createCapability(sosCapability);
            // replace existing capability with the same name
            if (names.contains(c.getName())) {
                removeCapability(abstractProcess, c);
            }
            abstractProcess.addNewCapabilities().set(c);
        }
    }
    // set description
    if (sosAbstractProcess.isSetDescription() && !abstractProcess.isSetDescription()) {
        abstractProcess.addNewDescription().setStringValue(sosAbstractProcess.getDescription());
    }
    if (sosAbstractProcess.isSetName() && CollectionHelper.isNullOrEmpty(abstractProcess.getNameArray())) {
        // TODO check if override existing names
        addNamesToAbstractProcess(abstractProcess, sosAbstractProcess.getNames());
    }
    // set identification
    if (sosAbstractProcess.isSetIdentifications()) {
        abstractProcess.setIdentificationArray(createIdentification(sosAbstractProcess.getIdentifications()));
    }
    // set classification
    if (sosAbstractProcess.isSetClassifications()) {
        abstractProcess.setClassificationArray(createClassification(sosAbstractProcess.getClassifications()));
    }
    // set characteristics
    if (sosAbstractProcess.isSetCharacteristics()) {
        abstractProcess.setCharacteristicsArray(createCharacteristics(sosAbstractProcess.getCharacteristics()));
    }
    // set documentation
    if (sosAbstractProcess.isSetDocumentation() && CollectionHelper.isNullOrEmpty(abstractProcess.getDocumentationArray())) {
        abstractProcess.setDocumentationArray(createDocumentationArray(sosAbstractProcess.getDocumentation()));
    }
    // process
    if (sosAbstractProcess.isSetContact() && CollectionHelper.isNullOrEmpty(abstractProcess.getContactArray())) {
        ContactList contactList = createContactList(sosAbstractProcess.getContact());
        if (contactList != null && contactList.getMemberArray().length > 0) {
            abstractProcess.addNewContact().setContactList(contactList);
        }
    }
    // set keywords
    if (sosAbstractProcess.isSetKeywords()) {
        final List<String> keywords = sosAbstractProcess.getKeywords();
        final int length = abstractProcess.getKeywordsArray().length;
        for (int i = 0; i < length; ++i) {
            abstractProcess.removeKeywords(i);
        }
        abstractProcess.addNewKeywords().addNewKeywordList().setKeywordArray(keywords.toArray(new String[keywords.size()]));
    }
    if (sosAbstractProcess.isSetValidTime()) {
        if (abstractProcess.isSetValidTime()) {
            // remove existing validTime element
            final XmlCursor newCursor = abstractProcess.getValidTime().newCursor();
            newCursor.removeXml();
            newCursor.dispose();
        }
        final Time time = sosAbstractProcess.getMergedValidTime();
        final XmlObject xbtime = encodeObjectToXml(GmlConstants.NS_GML, time);
        if (time instanceof TimeInstant) {
            abstractProcess.addNewValidTime().addNewTimeInstant().set(xbtime);
        } else if (time instanceof TimePeriod) {
            abstractProcess.addNewValidTime().addNewTimePeriod().set(xbtime);
        }
    }
}
Also used : TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) Time(org.n52.shetland.ogc.gml.time.Time) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) ContactList(net.opengis.sensorML.x101.ContactListDocument.ContactList) SmlContactList(org.n52.shetland.ogc.sensorML.SmlContactList) XmlCursor(org.apache.xmlbeans.XmlCursor) SmlCapabilities(org.n52.shetland.ogc.sensorML.elements.SmlCapabilities) Capabilities(net.opengis.sensorML.x101.CapabilitiesDocument.Capabilities) SmlCapabilities(org.n52.shetland.ogc.sensorML.elements.SmlCapabilities) XmlObject(org.apache.xmlbeans.XmlObject) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Example 5 with Process

use of org.n52.shetland.inspire.ompr.Process in project arctic-sea by 52North.

the class SensorMLEncoderv20 method createComponents.

/**
 * Creates the components section of the SensorML description.
 *
 * @param sosComponents
 *            SOS SWE representation.
 *
 * @return encoded sml:components
 *
 * @throws EncodingException
 *             if the process encoding fails
 */
private ComponentListPropertyType createComponents(final List<SmlComponent> sosComponents) throws EncodingException {
    ComponentListPropertyType clpt = ComponentListPropertyType.Factory.newInstance(getXmlOptions());
    final ComponentListType clt = clpt.addNewComponentList();
    for (final SmlComponent sosSMLComponent : sosComponents) {
        final Component component = clt.addNewComponent();
        if (sosSMLComponent.isSetName()) {
            component.setName(sosSMLComponent.getName());
        }
        if (sosSMLComponent.isSetHref()) {
            component.setHref(sosSMLComponent.getHref());
            if (sosSMLComponent.isSetTitle()) {
                component.setTitle(sosSMLComponent.getTitle());
            }
        } else if (sosSMLComponent.isSetProcess()) {
            XmlObject xmlObject = encode(sosSMLComponent.getProcess(), EncodingContext.of(XmlBeansEncodingFlags.TYPE));
            // }
            if (xmlObject != null) {
                // AbstractProcessType xbProcess = null;
                // if (xmlObject instanceof AbstractProcessType) {
                // xbProcess = (AbstractProcessType) xmlObject;
                // } else {
                // throw new NoApplicableCodeException()
                // .withMessage("The sensor type is not supported by this
                // SOS");
                // }
                // TODO add feature/parentProcs/childProcs to component - is
                // this already done?
                // XmlObject substituteElement =
                // XmlHelper.substituteElement(component.addNewAbstractProcess(),
                // xmlObject);
                // substituteElement.set(xmlObject);
                substitute(component.addNewAbstractProcess(), xmlObject);
            }
        }
    }
    return clpt;
}
Also used : ComponentListPropertyType(net.opengis.sensorml.x20.ComponentListPropertyType) XmlObject(org.apache.xmlbeans.XmlObject) PhysicalComponent(org.n52.shetland.ogc.sensorML.v20.PhysicalComponent) SmlComponent(org.n52.shetland.ogc.sensorML.elements.SmlComponent) Component(net.opengis.sensorml.x20.ComponentListType.Component) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) ComponentListType(net.opengis.sensorml.x20.ComponentListType) SmlComponent(org.n52.shetland.ogc.sensorML.elements.SmlComponent)

Aggregations

Process (org.n52.shetland.inspire.ompr.Process)9 XmlObject (org.apache.xmlbeans.XmlObject)6 Test (org.junit.Test)3 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)2 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)2 AbtractProcessDecodingTest (org.n52.svalbard.decode.AbtractProcessDecodingTest)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 IdentifierType (eu.europa.ec.inspire.schemas.base.x33.IdentifierType)1 ProcessDocument (eu.europa.ec.inspire.schemas.ompr.x30.ProcessDocument)1 ProcessPropertyType (eu.europa.ec.inspire.schemas.ompr.x30.ProcessPropertyType)1 ProcessType (eu.europa.ec.inspire.schemas.ompr.x30.ProcessType)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 AbstractComponentType (net.opengis.sensorML.x101.AbstractComponentType)1 AbstractDerivableComponentType (net.opengis.sensorML.x101.AbstractDerivableComponentType)1 AbstractProcessType (net.opengis.sensorML.x101.AbstractProcessType)1 Capabilities (net.opengis.sensorML.x101.CapabilitiesDocument.Capabilities)1 ComponentType (net.opengis.sensorML.x101.ComponentType)1