Search in sources :

Example 1 with OrderParameter

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);
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) OrderParameter(com.emc.storageos.db.client.model.uimodels.OrderParameter) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) URI(java.net.URI) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 2 with OrderParameter

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;
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) ServiceDescriptor(com.emc.sa.descriptor.ServiceDescriptor) WorkflowServiceDescriptor(com.emc.sa.catalog.WorkflowServiceDescriptor) OrderParameter(com.emc.storageos.db.client.model.uimodels.OrderParameter) CatalogService(com.emc.storageos.db.client.model.uimodels.CatalogService) URIUtil.asString(com.emc.storageos.db.client.URIUtil.asString)

Example 3 with OrderParameter

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;
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) OrderParameter(com.emc.storageos.db.client.model.uimodels.OrderParameter) ArrayList(java.util.ArrayList) OrderRestRep(com.emc.vipr.model.catalog.OrderRestRep)

Example 4 with OrderParameter

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;
}
Also used : OrderParameter(com.emc.storageos.db.client.model.uimodels.OrderParameter) ArrayList(java.util.ArrayList) OrderParameter(com.emc.storageos.db.client.model.uimodels.OrderParameter) Parameter(com.emc.vipr.model.catalog.Parameter)

Example 5 with OrderParameter

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;
}
Also used : OrderParameter(com.emc.storageos.db.client.model.uimodels.OrderParameter) OrderRestRep(com.emc.vipr.model.catalog.OrderRestRep) OrderParameter(com.emc.storageos.db.client.model.uimodels.OrderParameter) Parameter(com.emc.vipr.model.catalog.Parameter)

Aggregations

OrderParameter (com.emc.storageos.db.client.model.uimodels.OrderParameter)15 Order (com.emc.storageos.db.client.model.uimodels.Order)7 CatalogService (com.emc.storageos.db.client.model.uimodels.CatalogService)3 ExecutionState (com.emc.storageos.db.client.model.uimodels.ExecutionState)3 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)2 OrderRestRep (com.emc.vipr.model.catalog.OrderRestRep)2 Parameter (com.emc.vipr.model.catalog.Parameter)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Consumes (javax.ws.rs.Consumes)2 Path (javax.ws.rs.Path)2 Test (org.junit.Test)2 WorkflowServiceDescriptor (com.emc.sa.catalog.WorkflowServiceDescriptor)1 ServiceDescriptor (com.emc.sa.descriptor.ServiceDescriptor)1 BaseModelTest (com.emc.sa.model.BaseModelTest)1 ModelClient (com.emc.sa.model.dao.ModelClient)1 URIUtil.asString (com.emc.storageos.db.client.URIUtil.asString)1 ExecutionLog (com.emc.storageos.db.client.model.uimodels.ExecutionLog)1 ExecutionTaskLog (com.emc.storageos.db.client.model.uimodels.ExecutionTaskLog)1