Search in sources :

Example 1 with BusinessCardServerAPI

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

the class APIExecutorBusinessCardDelete 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 sServiceGroupID = aPathVariables.get(SMPRestFilter.PARAM_SERVICE_GROUP_ID);
    final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, sServiceGroupID);
    // Is the writable API disabled?
    if (SMPMetaManager.getSettings().isRESTWritableAPIDisabled()) {
        throw new SMPPreconditionFailedException("The writable REST API is disabled. deleteBusinessCard will not be executed", aDataProvider.getCurrentURI());
    }
    if (!SMPMetaManager.getSettings().isDirectoryIntegrationEnabled()) {
        // PD integration is disabled
        throw new SMPPreconditionFailedException("The " + SMPWebAppConfiguration.getDirectoryName() + " integration is disabled. deleteBusinessCard will not be executed", aDataProvider.getCurrentURI());
    }
    final BasicAuthClientCredentials aBasicAuth = getMandatoryAuth(aRequestScope.headers());
    new BusinessCardServerAPI(aDataProvider).deleteBusinessCard(sServiceGroupID, aBasicAuth);
    aUnifiedResponse.setStatus(CHttp.HTTP_OK);
}
Also used : SMPPreconditionFailedException(com.helger.phoss.smp.exception.SMPPreconditionFailedException) BasicAuthClientCredentials(com.helger.http.basicauth.BasicAuthClientCredentials) BusinessCardServerAPI(com.helger.phoss.smp.restapi.BusinessCardServerAPI) ISMPServerAPIDataProvider(com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider)

Example 2 with BusinessCardServerAPI

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

the class APIExecutorBusinessCardGet 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 sServiceGroupID = aPathVariables.get(SMPRestFilter.PARAM_SERVICE_GROUP_ID);
    final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, sServiceGroupID);
    if (!SMPMetaManager.getSettings().isDirectoryIntegrationEnabled()) {
        // PD integration is disabled
        throw new SMPPreconditionFailedException("The " + SMPWebAppConfiguration.getDirectoryName() + " integration is disabled. getBusinessCard will not be executed", aDataProvider.getCurrentURI());
    }
    // getBusinessCard throws an exception if non is found
    final PD3BusinessCardType ret = new BusinessCardServerAPI(aDataProvider).getBusinessCard(sServiceGroupID);
    final byte[] aBytes = new PD3BusinessCardMarshaller().getAsBytes(ret);
    aUnifiedResponse.setContent(aBytes).setMimeType(CMimeType.TEXT_XML).setCharset(XMLWriterSettings.DEFAULT_XML_CHARSET_OBJ);
}
Also used : SMPPreconditionFailedException(com.helger.phoss.smp.exception.SMPPreconditionFailedException) PD3BusinessCardType(com.helger.pd.businesscard.v3.PD3BusinessCardType) BusinessCardServerAPI(com.helger.phoss.smp.restapi.BusinessCardServerAPI) ISMPServerAPIDataProvider(com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider) PD3BusinessCardMarshaller(com.helger.pd.businesscard.v3.PD3BusinessCardMarshaller)

Example 3 with BusinessCardServerAPI

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

the class APIExecutorBusinessCardPut 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 sServiceGroupID = aPathVariables.get(SMPRestFilter.PARAM_SERVICE_GROUP_ID);
    final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, sServiceGroupID);
    // Is the writable API disabled?
    if (SMPMetaManager.getSettings().isRESTWritableAPIDisabled()) {
        throw new SMPPreconditionFailedException("The writable REST API is disabled. saveBusinessCard will not be executed", aDataProvider.getCurrentURI());
    }
    if (!SMPMetaManager.getSettings().isDirectoryIntegrationEnabled()) {
        // PD integration is disabled
        throw new SMPPreconditionFailedException("The " + SMPWebAppConfiguration.getDirectoryName() + " integration is disabled. saveBusinessCard will not be executed", aDataProvider.getCurrentURI());
    }
    // Parse main payload
    final byte[] aPayload = StreamHelper.getAllBytes(aRequestScope.getRequest().getInputStream());
    final PDBusinessCard aBC = PDBusinessCardHelper.parseBusinessCard(aPayload, (Charset) null);
    if (aBC == null) {
        // Cannot parse
        throw new SMPBadRequestException("Failed to parse XML payload as BusinessCard.", aDataProvider.getCurrentURI());
    }
    final BasicAuthClientCredentials aBasicAuth = getMandatoryAuth(aRequestScope.headers());
    final ESuccess eSuccess = new BusinessCardServerAPI(aDataProvider).createBusinessCard(sServiceGroupID, aBC, aBasicAuth);
    if (eSuccess.isFailure())
        aUnifiedResponse.setStatus(CHttp.HTTP_INTERNAL_SERVER_ERROR);
    else
        aUnifiedResponse.setStatus(CHttp.HTTP_OK);
}
Also used : ESuccess(com.helger.commons.state.ESuccess) SMPPreconditionFailedException(com.helger.phoss.smp.exception.SMPPreconditionFailedException) PDBusinessCard(com.helger.pd.businesscard.generic.PDBusinessCard) SMPBadRequestException(com.helger.phoss.smp.exception.SMPBadRequestException) BasicAuthClientCredentials(com.helger.http.basicauth.BasicAuthClientCredentials) BusinessCardServerAPI(com.helger.phoss.smp.restapi.BusinessCardServerAPI) ISMPServerAPIDataProvider(com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider)

Aggregations

SMPPreconditionFailedException (com.helger.phoss.smp.exception.SMPPreconditionFailedException)3 BusinessCardServerAPI (com.helger.phoss.smp.restapi.BusinessCardServerAPI)3 ISMPServerAPIDataProvider (com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider)3 BasicAuthClientCredentials (com.helger.http.basicauth.BasicAuthClientCredentials)2 ESuccess (com.helger.commons.state.ESuccess)1 PDBusinessCard (com.helger.pd.businesscard.generic.PDBusinessCard)1 PD3BusinessCardMarshaller (com.helger.pd.businesscard.v3.PD3BusinessCardMarshaller)1 PD3BusinessCardType (com.helger.pd.businesscard.v3.PD3BusinessCardType)1 SMPBadRequestException (com.helger.phoss.smp.exception.SMPBadRequestException)1