Search in sources :

Example 21 with ISMPServerAPIDataProvider

use of com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider in project phoss-smp by phax.

the class APIExecutorServiceGroupGet method invokeAPI.

public void invokeAPI(@Nonnull final IAPIDescriptor aAPIDescriptor, @Nonnull @Nonempty final String sPath, @Nonnull final Map<String, String> aPathVariables, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final UnifiedResponse aUnifiedResponse) throws Exception {
    final String sPathServiceGroupID = aPathVariables.get(SMPRestFilter.PARAM_SERVICE_GROUP_ID);
    final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, sPathServiceGroupID);
    final byte[] aBytes;
    switch(SMPServerConfiguration.getRESTType()) {
        case PEPPOL:
            {
                final com.helger.xsds.peppol.smp1.ServiceGroupType ret = new SMPServerAPI(aDataProvider).getServiceGroup(sPathServiceGroupID);
                aBytes = new SMPMarshallerServiceGroupType(XML_SCHEMA_VALIDATION).getAsBytes(ret);
                break;
            }
        case OASIS_BDXR_V1:
            {
                final com.helger.xsds.bdxr.smp1.ServiceGroupType ret = new BDXR1ServerAPI(aDataProvider).getServiceGroup(sPathServiceGroupID);
                aBytes = new BDXR1MarshallerServiceGroupType(XML_SCHEMA_VALIDATION).getAsBytes(ret);
                break;
            }
        default:
            throw new UnsupportedOperationException("Unsupported REST type specified!");
    }
    if (aBytes == null) {
        // Internal error serializing the payload
        throw new SMPInternalErrorException("Failed to convert the returned ServiceGroup to XML");
    }
    aUnifiedResponse.setContent(aBytes).setMimeType(CMimeType.TEXT_XML).setCharset(XMLWriterSettings.DEFAULT_XML_CHARSET_OBJ);
}
Also used : SMPServerAPI(com.helger.phoss.smp.restapi.SMPServerAPI) BDXR1MarshallerServiceGroupType(com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceGroupType) SMPMarshallerServiceGroupType(com.helger.smpclient.peppol.marshal.SMPMarshallerServiceGroupType) BDXR1ServerAPI(com.helger.phoss.smp.restapi.BDXR1ServerAPI) SMPInternalErrorException(com.helger.phoss.smp.exception.SMPInternalErrorException) ISMPServerAPIDataProvider(com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider) SMPMarshallerServiceGroupType(com.helger.smpclient.peppol.marshal.SMPMarshallerServiceGroupType) BDXR1MarshallerServiceGroupType(com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceGroupType)

Example 22 with ISMPServerAPIDataProvider

use of com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider in project phoss-smp by phax.

the class APIExecutorServiceGroupPut method invokeAPI.

public void invokeAPI(@Nonnull final IAPIDescriptor aAPIDescriptor, @Nonnull @Nonempty final String sPath, @Nonnull final Map<String, String> aPathVariables, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final UnifiedResponse aUnifiedResponse) throws Exception {
    final String sPathServiceGroupID = aPathVariables.get(SMPRestFilter.PARAM_SERVICE_GROUP_ID);
    final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, sPathServiceGroupID);
    // Is the writable API disabled?
    if (SMPMetaManager.getSettings().isRESTWritableAPIDisabled()) {
        throw new SMPPreconditionFailedException("The writable REST API is disabled. saveServiceGroup will not be executed", aDataProvider.getCurrentURI());
    }
    // Parse main payload
    final byte[] aPayload = StreamHelper.getAllBytes(aRequestScope.getRequest().getInputStream());
    final Document aServiceGroupDoc = DOMReader.readXMLDOM(aPayload);
    if (aServiceGroupDoc == null) {
        throw new SMPBadRequestException("Failed to parse provided payload as XML", aDataProvider.getCurrentURI());
    }
    final BasicAuthClientCredentials aBasicAuth = getMandatoryAuth(aRequestScope.headers());
    final boolean bCreateInSML = !"false".equalsIgnoreCase(aRequestScope.params().getAsString("create-in-sml"));
    ESuccess eSuccess = ESuccess.FAILURE;
    switch(SMPServerConfiguration.getRESTType()) {
        case PEPPOL:
            {
                final com.helger.xsds.peppol.smp1.ServiceGroupType aServiceGroup = new SMPMarshallerServiceGroupType(XML_SCHEMA_VALIDATION).read(aServiceGroupDoc);
                if (aServiceGroup != null) {
                    new SMPServerAPI(aDataProvider).saveServiceGroup(sPathServiceGroupID, aServiceGroup, bCreateInSML, aBasicAuth);
                    eSuccess = ESuccess.SUCCESS;
                }
                break;
            }
        case OASIS_BDXR_V1:
            {
                final com.helger.xsds.bdxr.smp1.ServiceGroupType aServiceGroup = new BDXR1MarshallerServiceGroupType(XML_SCHEMA_VALIDATION).read(aServiceGroupDoc);
                if (aServiceGroup != null) {
                    new BDXR1ServerAPI(aDataProvider).saveServiceGroup(sPathServiceGroupID, aServiceGroup, bCreateInSML, aBasicAuth);
                    eSuccess = ESuccess.SUCCESS;
                }
                break;
            }
        default:
            throw new UnsupportedOperationException("Unsupported REST type specified!");
    }
    if (eSuccess.isFailure())
        aUnifiedResponse.setStatus(CHttp.HTTP_INTERNAL_SERVER_ERROR);
    else
        aUnifiedResponse.setStatus(CHttp.HTTP_OK).disableCaching();
}
Also used : ESuccess(com.helger.commons.state.ESuccess) SMPBadRequestException(com.helger.phoss.smp.exception.SMPBadRequestException) SMPServerAPI(com.helger.phoss.smp.restapi.SMPServerAPI) BDXR1MarshallerServiceGroupType(com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceGroupType) SMPMarshallerServiceGroupType(com.helger.smpclient.peppol.marshal.SMPMarshallerServiceGroupType) BDXR1ServerAPI(com.helger.phoss.smp.restapi.BDXR1ServerAPI) Document(org.w3c.dom.Document) SMPPreconditionFailedException(com.helger.phoss.smp.exception.SMPPreconditionFailedException) BasicAuthClientCredentials(com.helger.http.basicauth.BasicAuthClientCredentials) ISMPServerAPIDataProvider(com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider) SMPMarshallerServiceGroupType(com.helger.smpclient.peppol.marshal.SMPMarshallerServiceGroupType) BDXR1MarshallerServiceGroupType(com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceGroupType)

Example 23 with ISMPServerAPIDataProvider

use of com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider in project phoss-smp by phax.

the class APIExecutorServiceMetadataDeleteAll method invokeAPI.

public void invokeAPI(@Nonnull final IAPIDescriptor aAPIDescriptor, @Nonnull @Nonempty final String sPath, @Nonnull final Map<String, String> aPathVariables, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final UnifiedResponse aUnifiedResponse) throws Exception {
    final String sPathServiceGroupID = aPathVariables.get(SMPRestFilter.PARAM_SERVICE_GROUP_ID);
    final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, sPathServiceGroupID);
    // Is the writable API disabled?
    if (SMPMetaManager.getSettings().isRESTWritableAPIDisabled()) {
        throw new SMPPreconditionFailedException("The writable REST API is disabled. deleteServiceRegistrations will not be executed.", aDataProvider.getCurrentURI());
    }
    final BasicAuthClientCredentials aBasicAuth = getMandatoryAuth(aRequestScope.headers());
    switch(SMPServerConfiguration.getRESTType()) {
        case PEPPOL:
            new SMPServerAPI(aDataProvider).deleteServiceRegistrations(sPathServiceGroupID, aBasicAuth);
            break;
        case OASIS_BDXR_V1:
            new BDXR1ServerAPI(aDataProvider).deleteServiceRegistrations(sPathServiceGroupID, aBasicAuth);
            break;
        default:
            throw new UnsupportedOperationException("Unsupported REST type specified!");
    }
    aUnifiedResponse.setStatus(HttpServletResponse.SC_OK).disableCaching();
}
Also used : SMPPreconditionFailedException(com.helger.phoss.smp.exception.SMPPreconditionFailedException) BasicAuthClientCredentials(com.helger.http.basicauth.BasicAuthClientCredentials) SMPServerAPI(com.helger.phoss.smp.restapi.SMPServerAPI) ISMPServerAPIDataProvider(com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider) BDXR1ServerAPI(com.helger.phoss.smp.restapi.BDXR1ServerAPI)

Example 24 with ISMPServerAPIDataProvider

use of com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider in project phoss-smp by phax.

the class APIExecutorUserListGet method invokeAPI.

public void invokeAPI(@Nonnull final IAPIDescriptor aAPIDescriptor, @Nonnull @Nonempty final String sPath, @Nonnull final Map<String, String> aPathVariables, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final UnifiedResponse aUnifiedResponse) throws Exception {
    final String sPathUserID = aPathVariables.get(SMPRestFilter.PARAM_USER_ID);
    // No service group available
    final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, null);
    final BasicAuthClientCredentials aCredentials = getMandatoryAuth(aRequestScope.headers());
    final byte[] aBytes;
    switch(SMPServerConfiguration.getRESTType()) {
        case PEPPOL:
            {
                // Unspecified extension
                final com.helger.xsds.peppol.smp1.ServiceGroupReferenceListType ret = new SMPServerAPI(aDataProvider).getServiceGroupReferenceList(sPathUserID, aCredentials);
                aBytes = new SMPMarshallerServiceGroupReferenceListType(XML_SCHEMA_VALIDATION).getAsBytes(ret);
                break;
            }
        case OASIS_BDXR_V1:
            {
                // Unspecified extension
                final com.helger.xsds.bdxr.smp1.ServiceGroupReferenceListType ret = new BDXR1ServerAPI(aDataProvider).getServiceGroupReferenceList(sPathUserID, aCredentials);
                aBytes = new BDXR1MarshallerServiceGroupReferenceListType(XML_SCHEMA_VALIDATION).getAsBytes(ret);
                break;
            }
        default:
            throw new UnsupportedOperationException("Unsupported REST type specified!");
    }
    if (aBytes == null) {
        // Internal error serializing the payload
        throw new SMPInternalErrorException("Failed to convert the returned CompleteServiceGroup to XML");
    }
    aUnifiedResponse.setContent(aBytes).setMimeType(CMimeType.TEXT_XML);
}
Also used : SMPServerAPI(com.helger.phoss.smp.restapi.SMPServerAPI) SMPMarshallerServiceGroupReferenceListType(com.helger.smpclient.peppol.marshal.SMPMarshallerServiceGroupReferenceListType) BDXR1MarshallerServiceGroupReferenceListType(com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceGroupReferenceListType) SMPMarshallerServiceGroupReferenceListType(com.helger.smpclient.peppol.marshal.SMPMarshallerServiceGroupReferenceListType) BDXR1ServerAPI(com.helger.phoss.smp.restapi.BDXR1ServerAPI) BasicAuthClientCredentials(com.helger.http.basicauth.BasicAuthClientCredentials) SMPInternalErrorException(com.helger.phoss.smp.exception.SMPInternalErrorException) ISMPServerAPIDataProvider(com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider) BDXR1MarshallerServiceGroupReferenceListType(com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceGroupReferenceListType)

Aggregations

ISMPServerAPIDataProvider (com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider)24 SMPPreconditionFailedException (com.helger.phoss.smp.exception.SMPPreconditionFailedException)18 BasicAuthClientCredentials (com.helger.http.basicauth.BasicAuthClientCredentials)15 SMPBadRequestException (com.helger.phoss.smp.exception.SMPBadRequestException)11 BDXR1ServerAPI (com.helger.phoss.smp.restapi.BDXR1ServerAPI)9 SMPServerAPI (com.helger.phoss.smp.restapi.SMPServerAPI)9 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)8 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)8 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)6 IMicroDocument (com.helger.xml.microdom.IMicroDocument)6 CMimeType (com.helger.commons.mime.CMimeType)5 MimeType (com.helger.commons.mime.MimeType)5 SMPInternalErrorException (com.helger.phoss.smp.exception.SMPInternalErrorException)5 XMLWriterSettings (com.helger.xml.serialize.write.XMLWriterSettings)5 StopWatch (com.helger.commons.timing.StopWatch)4 IJsonObject (com.helger.json.IJsonObject)4 JsonWriter (com.helger.json.serialize.JsonWriter)4 ISMPParticipantMigration (com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration)4 ISMPParticipantMigrationManager (com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigrationManager)4 ESuccess (com.helger.commons.state.ESuccess)3