use of com.emc.vipr.model.catalog.ServiceFieldRestRep in project coprhd-controller by CoprHD.
the class EditCatalog method addFieldOptions.
private static void addFieldOptions(String baseService) {
// Base service may be null for a new service
if (StringUtils.isNotBlank(baseService)) {
ServiceDescriptorRestRep serviceDescriptor = getServiceDescriptorForEditing(baseService);
// Load any Asset Options for root fields so they are rendered directly onto the form
List<ServiceFieldRestRep> fields = ServiceDescriptorUtils.getAllFieldList(serviceDescriptor.getItems());
for (ServiceFieldRestRep field : fields) {
if (field.isAsset() && field.isLockable()) {
try {
List<AssetOption> options = AssetOptionUtils.getAssetOptions(field.getAssetType());
request.current().args.put(field.getType() + "-options", options);
} catch (RuntimeException e) {
request.current().args.put(field.getType() + "-error", e.getMessage());
}
}
}
}
}
use of com.emc.vipr.model.catalog.ServiceFieldRestRep in project coprhd-controller by CoprHD.
the class OrderExecution method createOrder.
@Util
public static OrderCreateParam createOrder(CatalogServiceRestRep service, ServiceDescriptorRestRep descriptor, Map<String, String> parameters) {
OrderCreateParam order = new OrderCreateParam();
order.setTenantId(uri(Models.currentAdminTenant()));
order.setCatalogService(service.getId());
List<Parameter> orderParameters = Lists.newArrayList();
List<ServiceFieldRestRep> fields = ServiceDescriptorUtils.getAllFieldList(descriptor.getItems());
for (ServiceFieldRestRep field : fields) {
String value = parameters.get(field.getName());
if (StringUtils.isNotBlank(value)) {
orderParameters.add(createOrderParameter(field, value));
}
}
order.setParameters(orderParameters);
return order;
}
use of com.emc.vipr.model.catalog.ServiceFieldRestRep in project coprhd-controller by CoprHD.
the class Services method showForm.
/**
* Builds a form for a particular service
*/
public static void showForm(String serviceId) {
TenantSelector.addRenderArgs();
boolean isTestWorkflow = false;
CatalogServiceRestRep service = CatalogServiceUtils.getCatalogService(uri(serviceId));
if (null == service.getCatalogCategory()) {
isTestWorkflow = true;
}
List<CatalogServiceFieldRestRep> serviceFields = service.getCatalogServiceFields();
// If serviceDescriptor is null render another template that spells out the problem for the user.
ServiceDescriptorRestRep serviceDescriptor = service.getServiceDescriptor();
if (serviceDescriptor == null) {
corruptedService(service);
}
Map<String, Object> fieldOptions = new HashMap<String, Object>();
// add the breadcrumb
if (!isTestWorkflow) {
addBreadCrumbToRenderArgs(service);
} else {
addBreadCrumbToRenderArgs(service, Common.reverseRoute(WorkflowBuilder.class, "view"));
}
// Mark the service as recently used
// RecentUtils.usedService(service);
Map<String, AssetFieldDescriptor> assetFieldDescriptors = ServiceFormUtils.createAssetFieldDescriptors(serviceDescriptor);
// Calculate default values for all fields
Map<String, String> defaultValues = getDefaultValues(serviceDescriptor);
// Calculate asset parameters for any fields that are overridden
Map<String, String> overriddenValues = getOverriddenValues(service);
Map<String, String> availableAssets = getAvailableAssets(assetFieldDescriptors, overriddenValues);
// Load any Asset Options for root fields so they are rendered directly onto the form
List<ServiceFieldRestRep> allFields = ServiceDescriptorUtils.getAllFieldList(serviceDescriptor.getItems());
for (ServiceFieldRestRep field : allFields) {
if (field.isAsset()) {
// Compute to see if we have all dependencies. We have all dependencies if fieldsWeDependOn is empty
// or it only contains fields we have in our overridden values.
AssetFieldDescriptor fieldDescriptor = assetFieldDescriptors.get(field.getName());
boolean hasAllDependencies = overriddenValues.keySet().containsAll(fieldDescriptor.fieldsWeDependOn);
boolean isOverridden = overriddenValues.containsKey(field.getName());
if (hasAllDependencies && !isOverridden) {
List<AssetOption> options = getAssetOptions(field, availableAssets);
fieldOptions.put(field.getType() + "-options", options);
// If a required field is missing any options, display a warning message
if (options.isEmpty() && field.isRequired() && !field.getType().equalsIgnoreCase("field")) {
flash.put("rawWarning", MessagesUtils.get("service.missingAssets", field.getLabel()));
}
}
}
}
Gson gson = new Gson();
String defaultValuesJSON = gson.toJson(defaultValues);
String assetFieldDescriptorsJSON = gson.toJson(assetFieldDescriptors);
String overriddenValuesJSON = gson.toJson(overriddenValues);
boolean showForm = true;
// Display an error message and don't display the form if an execution window is required but none are defined
if (Boolean.TRUE.equals(service.isExecutionWindowRequired()) && !hasExecutionWindows()) {
flash.error(MessagesUtils.get("service.noExecutionWindows"));
showForm = false;
}
renderArgs.data.putAll(new ImmutableMap.Builder<String, Object>().put("service", service).put("serviceFields", serviceFields).put("serviceDescriptor", serviceDescriptor).put("assetFieldDescriptorsJSON", assetFieldDescriptorsJSON).put("defaultValuesJSON", defaultValuesJSON).put("overriddenValuesJSON", overriddenValuesJSON).put("showForm", new Boolean(showForm)).build());
// Adding to request, as renderArgs can't be dynamically named
request.current().args.putAll(fieldOptions);
copyRenderArgsToAngular();
angularRenderArgs().putAll(fieldOptions);
angularRenderArgs().putAll(ImmutableMap.of("assetFieldDescriptors", assetFieldDescriptors, "defaultValues", defaultValues, "overriddenValues", overriddenValues));
render();
}
use of com.emc.vipr.model.catalog.ServiceFieldRestRep in project coprhd-controller by CoprHD.
the class ServiceFormUtils method findFieldByAssetType.
/**
* Finds a field by asset type, first searching the fields list and falling back to a lookup in the provided fields.
*
* @param assetType
* the asset type.
* @param fields
* the fields to search.
* @param providedFields
* the fields provided by the parent, mapped by asset type.
* @return the matching service field.
*
* @throws IllegalArgumentException
* if there is no matching field with the desired type.
*/
private static ServiceFieldRestRep findFieldByAssetType(String assetType, Collection<ServiceFieldRestRep> fields, Map<String, ServiceFieldRestRep> providedFields) {
ServiceFieldRestRep field = findFieldByAssetType(assetType, fields);
if (field != null) {
return field;
}
field = providedFields.get(assetType);
if (field != null) {
return field;
}
throw new IllegalArgumentException("No Field of type " + assetType);
}
use of com.emc.vipr.model.catalog.ServiceFieldRestRep in project coprhd-controller by CoprHD.
the class ServiceFormUtils method createAssetFields.
/**
* Creates asset field descriptors for the list of asset fields, with access to the additional fields provided by
* the parent.
*
* @param fields
* the asset fields for which to create descriptors.
* @param providedFields
* the asset fields provided by the parent, mapped by asset type.
* @return the map of field name->AssetFieldDescriptor.
*/
private static Map<String, AssetFieldDescriptor> createAssetFields(List<ServiceFieldRestRep> fields, Map<String, ServiceFieldRestRep> providedFields) {
Map<String, AssetFieldDescriptor> assetFields = Maps.newHashMap();
Set<String> availableTypes = Sets.newHashSet(ServiceFieldRestRep.getAssetTypes(providedFields.values()));
availableTypes.addAll(ServiceFieldRestRep.getAssetTypes(fields));
for (ServiceFieldRestRep field : fields) {
String assetType = field.getAssetType();
List<String> dependencies = Lists.newArrayList();
for (String requiredType : AssetOptionsApi.calculateAssetDependencies(assetType, availableTypes)) {
ServiceFieldRestRep dep = findFieldByAssetType(requiredType, fields, providedFields);
dependencies.add(dep.getName());
}
AssetFieldDescriptor assetField = createAssetField(field, dependencies);
assetFields.put(field.getName(), assetField);
}
return assetFields;
}
Aggregations