Search in sources :

Example 6 with Parameter

use of com.emc.vipr.model.catalog.Parameter 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 7 with Parameter

use of com.emc.vipr.model.catalog.Parameter 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)

Example 8 with Parameter

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

the class Orders method addParametersToFlash.

@Util
private static void addParametersToFlash(OrderRestRep order) {
    CatalogServiceRestRep service = CatalogServiceUtils.getCatalogService(uri(order.getCatalogService().getId().toString()));
    HashMap<String, String> tableParams = new HashMap<String, String>();
    if (service == null || service.getServiceDescriptor() == null) {
        flash.error("order.submitFailedWithDetail", " The Workflow or Service Descriptor is deleted");
        Logger.error("Service Descriptor not found");
        throw new IllegalStateException("No Service Descriptor found. Might be Customservices Workflow  is deleted ");
    }
    for (ServiceItemRestRep item : service.getServiceDescriptor().getItems()) {
        if (item.isTable()) {
            for (ServiceFieldRestRep tableItem : ((ServiceFieldTableRestRep) item).getItems()) {
                tableParams.put(tableItem.getName(), item.getName());
            }
        }
    }
    for (Parameter parameter : order.getParameters()) {
        // Do not add encrypted values to the flash scope
        if (parameter.isEncrypted()) {
            continue;
        }
        List<String> values = TextUtils.parseCSV(parameter.getValue());
        for (int i = 0; i < values.size(); i++) {
            String value = values.get(i);
            String name = parameter.getLabel();
            if (tableParams.containsKey(name)) {
                name = tableParams.get(name) + "[" + i + "]." + name;
            }
            flash.put(name, value);
        }
    }
}
Also used : ServiceItemRestRep(com.emc.vipr.model.catalog.ServiceItemRestRep) ServiceFieldTableRestRep(com.emc.vipr.model.catalog.ServiceFieldTableRestRep) HashMap(java.util.HashMap) ServiceFieldRestRep(com.emc.vipr.model.catalog.ServiceFieldRestRep) Parameter(com.emc.vipr.model.catalog.Parameter) CatalogServiceRestRep(com.emc.vipr.model.catalog.CatalogServiceRestRep) BourneUtil(util.BourneUtil) TaskUtil(com.emc.vipr.client.core.impl.TaskUtil) Util(play.mvc.Util)

Aggregations

Parameter (com.emc.vipr.model.catalog.Parameter)8 OrderParameter (com.emc.storageos.db.client.model.uimodels.OrderParameter)3 CatalogServiceRestRep (com.emc.vipr.model.catalog.CatalogServiceRestRep)2 ServiceFieldRestRep (com.emc.vipr.model.catalog.ServiceFieldRestRep)2 Util (play.mvc.Util)2 ServiceField (com.emc.sa.descriptor.ServiceField)1 URIUtil.asString (com.emc.storageos.db.client.URIUtil.asString)1 TaskUtil (com.emc.vipr.client.core.impl.TaskUtil)1 CatalogServiceFieldRestRep (com.emc.vipr.model.catalog.CatalogServiceFieldRestRep)1 OrderCreateParam (com.emc.vipr.model.catalog.OrderCreateParam)1 OrderRestRep (com.emc.vipr.model.catalog.OrderRestRep)1 ScheduleCycleType (com.emc.vipr.model.catalog.ScheduleCycleType)1 ScheduleInfo (com.emc.vipr.model.catalog.ScheduleInfo)1 ScheduledEventCreateParam (com.emc.vipr.model.catalog.ScheduledEventCreateParam)1 ServiceFieldTableRestRep (com.emc.vipr.model.catalog.ServiceFieldTableRestRep)1 ServiceItemRestRep (com.emc.vipr.model.catalog.ServiceItemRestRep)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 DateTime (org.joda.time.DateTime)1 BourneUtil (util.BourneUtil)1