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