use of com.emc.storageos.db.client.model.uimodels.OrderParameter in project coprhd-controller by CoprHD.
the class OrderService method createOrder.
@POST
@Path("")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public OrderRestRep createOrder(OrderCreateParam createParam) {
StorageOSUser user = getUserFromContext();
URI tenantId = createParam.getTenantId();
if (tenantId != null) {
verifyAuthorizedInTenantOrg(tenantId, user);
} else {
tenantId = uri(user.getTenantId());
}
Order order = createNewOrder(user, tenantId, createParam);
orderManager.processOrder(order);
order = orderManager.getOrderById(order.getId());
List<OrderParameter> orderParameters = orderManager.getOrderParameters(order.getId());
auditOpSuccess(OperationTypeEnum.CREATE_ORDER, order.auditParameters());
return map(order, orderParameters);
}
use of com.emc.storageos.db.client.model.uimodels.OrderParameter in project coprhd-controller by CoprHD.
the class OrderService method createNewOrder.
public Order createNewOrder(StorageOSUser user, URI tenantId, OrderCreateParam createParam) {
ArgValidator.checkFieldNotNull(createParam.getCatalogService(), "catalogService");
CatalogService service = catalogServiceManager.getCatalogServiceById(createParam.getCatalogService());
if (service == null) {
throw APIException.badRequests.orderServiceNotFound(asString(createParam.getCatalogService()));
}
final ServiceDescriptor descriptor = ServiceDescriptorUtil.getServiceDescriptorByName(serviceDescriptors, workflowServiceDescriptor, service.getBaseService());
if (descriptor == null) {
throw APIException.badRequests.orderServiceDescriptorNotFound(service.getBaseService());
}
// Getting and setting workflow document (if its workflow service)
if (null != descriptor.getWorkflowId()) {
final String workflowDocument = catalogServiceManager.getWorkflowDocument(service.getBaseService());
if (null == workflowDocument) {
throw APIException.badRequests.workflowNotFound(service.getBaseService());
}
createParam.setWorkflowDocument(workflowDocument);
}
Order order = createNewObject(tenantId, createParam);
addLockedFields(service.getId(), descriptor, createParam);
validateParameters(descriptor, createParam.getParameters(), service.getMaxSize());
List<OrderParameter> orderParams = createOrderParameters(order, createParam, encryptionProvider);
orderManager.createOrder(order, orderParams, user);
return order;
}
use of com.emc.storageos.db.client.model.uimodels.OrderParameter in project coprhd-controller by CoprHD.
the class OrderService method toOrders.
private List<OrderRestRep> toOrders(List<Order> orders, StorageOSUser user, boolean ordersOnly) {
List<OrderRestRep> orderList = new ArrayList();
List<OrderParameter> orderParameters = null;
for (Order order : orders) {
if (ordersOnly == false) {
orderParameters = orderManager.getOrderParameters(order.getId());
}
orderList.add(map(order, orderParameters));
}
return orderList;
}
use of com.emc.storageos.db.client.model.uimodels.OrderParameter in project coprhd-controller by CoprHD.
the class OrderMapper method createOrderParameters.
public static List<OrderParameter> createOrderParameters(Order order, OrderCreateParam param, EncryptionProvider encryption) {
List<OrderParameter> orderParams = new ArrayList<OrderParameter>();
if (param.getParameters() != null) {
int parameterIndex = 0;
for (Parameter parameter : param.getParameters()) {
OrderParameter orderParameter = new OrderParameter();
orderParameter.setSortedIndex(parameterIndex++);
orderParameter.setFriendlyLabel(parameter.getFriendlyLabel());
orderParameter.setLabel(parameter.getLabel());
orderParameter.setUserInput(parameter.isUserInput());
orderParameter.setEncrypted(parameter.isEncrypted());
if (parameter.isEncrypted()) {
// We have to treat this as a CSV value - pull the CSV
// apart, encrypt the pieces, re-CSV encode
List<String> values = Lists.newArrayList();
for (String value : TextUtils.parseCSV(parameter.getValue())) {
values.add(Base64.encodeBase64String(encryption.encrypt(value)));
}
String encryptedValue = TextUtils.formatCSV(values);
orderParameter.setFriendlyValue(ENCRYPTED_FIELD_MASK);
orderParameter.setValue(encryptedValue);
} else {
orderParameter.setFriendlyValue(parameter.getFriendlyValue());
orderParameter.setValue(parameter.getValue());
}
orderParameter.setOrderId(order.getId());
orderParams.add(orderParameter);
}
}
return orderParams;
}
use of com.emc.storageos.db.client.model.uimodels.OrderParameter in project coprhd-controller by CoprHD.
the class OrderMapper method map.
public static OrderRestRep map(Order from, List<OrderParameter> orderParameters) {
if (from == null) {
return null;
}
OrderRestRep to = new OrderRestRep();
mapDataObjectFields(from, to);
if (from.getCatalogServiceId() != null) {
to.setCatalogService(toRelatedResource(ResourceTypeEnum.CATALOG_SERVICE, from.getCatalogServiceId()));
}
if (from.getExecutionWindowId() != null) {
to.setExecutionWindow(toRelatedResource(ResourceTypeEnum.EXECUTION_WINDOW, from.getExecutionWindowId().getURI()));
}
to.setDateCompleted(from.getDateCompleted());
to.setMessage(from.getMessage());
to.setOrderNumber(from.getOrderNumber());
to.setSummary(from.getSummary());
to.setSubmittedBy(from.getSubmittedByUserId());
to.setOrderStatus(from.getOrderStatus());
if (StringUtils.isNotBlank(from.getTenant())) {
to.setTenant(toRelatedResource(ResourceTypeEnum.TENANT, uri(from.getTenant())));
}
to.setLastUpdated(from.getLastUpdated());
if (orderParameters != null) {
for (OrderParameter orderParameter : orderParameters) {
Parameter parameter = new Parameter();
parameter.setEncrypted(orderParameter.getEncrypted());
if (parameter.isEncrypted()) {
parameter.setFriendlyValue(ENCRYPTED_FIELD_MASK);
parameter.setValue(ENCRYPTED_FIELD_MASK);
} else {
parameter.setFriendlyValue(orderParameter.getFriendlyValue());
parameter.setValue(orderParameter.getValue());
}
parameter.setFriendlyLabel(orderParameter.getFriendlyLabel());
parameter.setLabel(orderParameter.getLabel());
to.getParameters().add(parameter);
}
}
if (from.getScheduledEventId() != null) {
to.setScheduledEventId(from.getScheduledEventId());
}
if (from.getScheduledTime() != null) {
to.setScheduledTime(from.getScheduledTime());
}
return to;
}
Aggregations