Example usage for com.amazonaws.services.certificatemanager.model InvalidStateException InvalidStateException

List of usage examples for com.amazonaws.services.certificatemanager.model InvalidStateException InvalidStateException

Introduction

In this page you can find the example usage for com.amazonaws.services.certificatemanager.model InvalidStateException InvalidStateException.

Prototype

public InvalidStateException(String message) 

Source Link

Document

Constructs a new InvalidStateException with the specified error message.

Usage

From source file:nl.kpmg.lcm.server.rest.client.version0.RemoteMetaDataController.java

License:Apache License

@POST
@Path("{lcm_id}/metadata/{metadata_id}")
@Produces({ "text/plain" })
@Consumes({ "application/json" })
@RolesAllowed({ Roles.ADMINISTRATOR, Roles.API_USER })
@ApiOperation(value = "Trigger transfer of data from remote Lcm.", notes = "Roles: " + Roles.ADMINISTRATOR
        + ", " + Roles.API_USER)
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK") })
public final Response trigger(@Context SecurityContext securityContext,
        @ApiParam(value = "Remote Lcm id.") @PathParam("lcm_id") final String lcmId,
        @ApiParam(value = "Metadata id on the Remote Lcm.") @PathParam("metadata_id") final String metadataId,
        @ApiParam(value = "Transfer details map Contains: "
                + "\"local-storage-id\",\"namespace-path\" and \"transfer-settings\".") Map payload)
        throws ServerException {
    AUDIT_LOGGER.info(userIdentifier.getUserDescription(securityContext, false)
            + " is trying to trigger a transfer of metadata with id: " + metadataId
            + " from remote LCM with id: " + lcmId + ".");

    Notification notification = validateTriggerParams(payload, lcmId, metadataId);

    if (notification.hasErrors()) {
        AUDIT_LOGGER.debug(userIdentifier.getUserDescription(securityContext, true)
                + " was unable to trigger a transfer of metadata with id: " + metadataId
                + " from remote LCM with id: " + lcmId + ". Error message: " + notification.errorMessage());
        throw new LcmValidationException(notification);
    }//from   w  w  w .jav  a2  s .com

    if (securityContext == null) {
        AUDIT_LOGGER.debug(userIdentifier.getUserDescription(securityContext, true)
                + " was unable to trigger a transfer of metadata with id: " + metadataId
                + " from remote LCM with id: " + lcmId + " because the security context is null. "
                + notification.errorMessage());
        throw new InvalidStateException("Security context is null!");
    }

    String localStorageId = (String) payload.get("local-storage-id");
    String namespacePath = (String) payload.get("namespace-path");

    String transferSettingsString = (String) payload.get("transfer-settings");

    TransferSettings transferSettings = null;
    if (transferSettingsString == null) {
        LOGGER.info("Unable to find TransferSettings object! Default settings will be used!");
        transferSettings = new TransferSettings();
    } else {
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            transferSettings = objectMapper.readValue(transferSettingsString, TransferSettings.class);
        } catch (IOException iae) {
            LOGGER.warn(
                    "Unable to parse TransferSettings object, most probably it has invalid structure! Default settings will be used!");
            transferSettings = new TransferSettings();
        }
    }
    User principal = (User) securityContext.getUserPrincipal();
    dataFetchTriggerService.scheduleDataFetchTask(lcmId, metadataId, localStorageId, transferSettings,
            namespacePath, principal.getName());

    AUDIT_LOGGER.info(userIdentifier.getUserDescription(securityContext, true)
            + " transfered successfully the metadata with id: " + metadataId + " from remote LCM with id: "
            + lcmId + ".");
    return Response.ok().build();
}