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);
}
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);
}
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);
}
Aggregations