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