Search in sources :

Example 6 with ApprovalRestRep

use of com.emc.vipr.model.catalog.ApprovalRestRep in project coprhd-controller by CoprHD.

the class NotificationManagerImpl method map.

public ApprovalRestRep map(ApprovalRequest from) {
    if (from == null) {
        return null;
    }
    ApprovalRestRep to = new ApprovalRestRep();
    mapDataObjectFields(from, to);
    if (from.getTenant() != null) {
        to.setTenant(toRelatedResource(ResourceTypeEnum.TENANT, uri(from.getTenant())));
    }
    if (from.getOrderId() != null) {
        to.setOrder(toRelatedResource(ResourceTypeEnum.ORDER, from.getOrderId()));
    }
    to.setApprovedBy(from.getApprovedBy());
    to.setDateActioned(from.getDateActioned());
    to.setMessage(from.getMessage());
    to.setApprovalStatus(from.getApprovalStatus());
    return to;
}
Also used : ApprovalRestRep(com.emc.vipr.model.catalog.ApprovalRestRep)

Example 7 with ApprovalRestRep

use of com.emc.vipr.model.catalog.ApprovalRestRep in project coprhd-controller by CoprHD.

the class NotificationManagerImpl method notifyApprovalService.

private void notifyApprovalService(String approvalUrl, Order order, ApprovalRequest approval) {
    try {
        ApprovalRestRep approvalRestRep = map(approval);
        ClientConfig config = new DefaultClientConfig();
        config.getClasses().add(JacksonJaxbJsonProvider.class);
        Client client = Client.create(config);
        WebResource.Builder webResource = client.resource(UriBuilder.fromUri(approvalUrl).build()).type(MediaType.APPLICATION_JSON);
        ClientResponse response = webResource.post(ClientResponse.class, approvalRestRep);
        if (isError(response)) {
            log.error(String.format("Approval POST failed: %s, %s %s", approvalUrl, response.getStatus(), response.getEntity(String.class)));
        } else {
            log.debug(String.format("Approval POST succeeded: %s, %s %s", approvalUrl, response.getStatus(), response.getEntity(String.class)));
        }
    } catch (ClientHandlerException e) {
        log.error(String.format("Approval POST failed: %s, %s, %s", approvalUrl, e.getCause(), e.getMessage()));
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) ApprovalRestRep(com.emc.vipr.model.catalog.ApprovalRestRep) WebResource(com.sun.jersey.api.client.WebResource) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) Client(com.sun.jersey.api.client.Client) CoordinatorClient(com.emc.storageos.coordinator.client.service.CoordinatorClient)

Example 8 with ApprovalRestRep

use of com.emc.vipr.model.catalog.ApprovalRestRep in project coprhd-controller by CoprHD.

the class ApprovalsApi method action.

private static void action(URI approvalId, String status, String message) {
    ApprovalUpdateParam updateParam = new ApprovalUpdateParam();
    updateParam.setApprovalStatus(status);
    updateParam.setMessage(message);
    getCatalogClient().approvals().update(approvalId, updateParam);
    ApprovalRestRep approval = getCatalogClient().approvals().get(approvalId);
    renderApi(newApprovalInfo(approval));
}
Also used : ApprovalUpdateParam(com.emc.vipr.model.catalog.ApprovalUpdateParam) ApprovalRestRep(com.emc.vipr.model.catalog.ApprovalRestRep)

Example 9 with ApprovalRestRep

use of com.emc.vipr.model.catalog.ApprovalRestRep in project coprhd-controller by CoprHD.

the class Approvals method edit.

public static void edit(String id) {
    ViPRCatalogClient2 catalog = getCatalogClient();
    ApprovalRestRep approval = catalog.approvals().get(uri(id));
    if (!approval.getTenant().getId().toString().equals(Security.getUserInfo().getTenant())) {
        Result result = new Unauthorized(MessagesUtils.get("approval.noTenantAccess", approval.getTenant().getId()));
        renderTemplate("errors/401.html", result);
    }
    OrderRestRep order = null;
    ScheduledEventRestRep scheduledEvent = null;
    Date scheduleStartDateTime = null;
    CatalogServiceRestRep service = null;
    if (approval != null) {
        order = getOrder(approval.getOrder());
        if (order != null) {
            service = getCatalogService(order.getCatalogService());
            URI scheduledEventId = order.getScheduledEventId();
            if (scheduledEventId != null) {
                scheduledEvent = getCatalogClient().orders().getScheduledEvent(scheduledEventId);
                String isoDateTimeStr = String.format("%sT%02d:%02d:00Z", scheduledEvent.getScheduleInfo().getStartDate(), scheduledEvent.getScheduleInfo().getHourOfDay(), scheduledEvent.getScheduleInfo().getMinuteOfHour());
                DateTime startDateTime = DateTime.parse(isoDateTimeStr);
                scheduleStartDateTime = startDateTime.toDate();
            }
        }
    }
    render(approval, order, service, scheduledEvent, scheduleStartDateTime);
}
Also used : ApprovalRestRep(com.emc.vipr.model.catalog.ApprovalRestRep) Unauthorized(play.mvc.results.Unauthorized) OrderRestRep(com.emc.vipr.model.catalog.OrderRestRep) ViPRCatalogClient2(com.emc.vipr.client.ViPRCatalogClient2) CatalogServiceRestRep(com.emc.vipr.model.catalog.CatalogServiceRestRep) ScheduledEventRestRep(com.emc.vipr.model.catalog.ScheduledEventRestRep) URI(java.net.URI) Date(java.util.Date) DateTime(org.joda.time.DateTime) Result(play.mvc.results.Result)

Example 10 with ApprovalRestRep

use of com.emc.vipr.model.catalog.ApprovalRestRep in project coprhd-controller by CoprHD.

the class Approvals method submit.

public static void submit(String id, ApprovalsForm approval) {
    ViPRCatalogClient2 catalog = getCatalogClient();
    ApprovalRestRep approvalRep = catalog.approvals().get(uri(id));
    OrderRestRep order = getOrder(approvalRep.getOrder());
    if (approvalRep.isPending()) {
        approval.validate("approval");
        if (Validation.hasErrors()) {
            Common.handleError();
        }
        if (isApprove(approval.getSubmit())) {
            approve(approvalRep, approval.getMessage());
            flash.put("success", MessagesUtils.get("approval.approve.message", order.getSubmittedBy()));
        } else if (isReject(approval.getSubmit())) {
            reject(approvalRep, approval.getMessage());
            flash.put("warn", MessagesUtils.get("approval.reject.message", order.getSubmittedBy()));
        }
    } else {
        flash.error(MessagesUtils.get("approval.notPending.error", order.getOrderNumber()));
    }
    index();
}
Also used : ApprovalRestRep(com.emc.vipr.model.catalog.ApprovalRestRep) OrderRestRep(com.emc.vipr.model.catalog.OrderRestRep) ViPRCatalogClient2(com.emc.vipr.client.ViPRCatalogClient2)

Aggregations

ApprovalRestRep (com.emc.vipr.model.catalog.ApprovalRestRep)10 ViPRCatalogClient2 (com.emc.vipr.client.ViPRCatalogClient2)4 OrderRestRep (com.emc.vipr.model.catalog.OrderRestRep)4 CatalogServiceRestRep (com.emc.vipr.model.catalog.CatalogServiceRestRep)3 URI (java.net.URI)2 CoordinatorClient (com.emc.storageos.coordinator.client.service.CoordinatorClient)1 ApprovalUpdateParam (com.emc.vipr.model.catalog.ApprovalUpdateParam)1 Reference (com.emc.vipr.model.catalog.Reference)1 ScheduledEventRestRep (com.emc.vipr.model.catalog.ScheduledEventRestRep)1 Client (com.sun.jersey.api.client.Client)1 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 WebResource (com.sun.jersey.api.client.WebResource)1 ClientConfig (com.sun.jersey.api.client.config.ClientConfig)1 DefaultClientConfig (com.sun.jersey.api.client.config.DefaultClientConfig)1 Date (java.util.Date)1 ApprovalRequestInfo (models.datatable.ApprovalsDataTable.ApprovalRequestInfo)1 DateTime (org.joda.time.DateTime)1 Util (play.mvc.Util)1 Result (play.mvc.results.Result)1