Search in sources :

Example 1 with CatalogServiceFieldRestRep

use of com.emc.vipr.model.catalog.CatalogServiceFieldRestRep 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();
}
Also used : AssetOption(com.emc.vipr.model.catalog.AssetOption) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) ImmutableMap(com.google.common.collect.ImmutableMap) CatalogServiceFieldRestRep(com.emc.vipr.model.catalog.CatalogServiceFieldRestRep) ServiceDescriptorRestRep(com.emc.vipr.model.catalog.ServiceDescriptorRestRep) AssetFieldDescriptor(util.ServiceFormUtils.AssetFieldDescriptor) CatalogServiceFieldRestRep(com.emc.vipr.model.catalog.CatalogServiceFieldRestRep) ServiceFieldRestRep(com.emc.vipr.model.catalog.ServiceFieldRestRep) CatalogServiceRestRep(com.emc.vipr.model.catalog.CatalogServiceRestRep)

Example 2 with CatalogServiceFieldRestRep

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

the class Services method getOverriddenValues.

/**
 * Gets the overridden (locked) values for the catalog service.
 *
 * @param service
 *            the service.
 * @return the overridden values.
 */
private static Map<String, String> getOverriddenValues(CatalogServiceRestRep service) {
    List<CatalogServiceFieldRestRep> serviceFields = service.getCatalogServiceFields();
    Map<String, String> overriddenValues = Maps.newHashMap();
    for (CatalogServiceFieldRestRep field : serviceFields) {
        boolean overridden = Boolean.TRUE.equals(field.getOverride());
        boolean hasValue = field.getValue() != null;
        if (overridden && hasValue) {
            overriddenValues.put(field.getName(), field.getValue());
        }
    }
    return overriddenValues;
}
Also used : CatalogServiceFieldRestRep(com.emc.vipr.model.catalog.CatalogServiceFieldRestRep)

Example 3 with CatalogServiceFieldRestRep

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

the class CatalogApi method serviceDescriptor.

public static void serviceDescriptor(String serviceId) {
    CatalogServiceRestRep service = CatalogServiceUtils.getCatalogService(uri(serviceId));
    ServiceDescriptorRestRep descriptor = service.getServiceDescriptor();
    // Remove any locked fields so user does not see things they cannot change
    for (CatalogServiceFieldRestRep catalogServiceField : service.getCatalogServiceFields()) {
        if (catalogServiceField.getOverride()) {
            ServiceFieldRestRep serviceField = ServiceDescriptorUtils.getField(descriptor, catalogServiceField.getName());
            descriptor.getItems().remove(serviceField);
        }
    }
    renderPrettyJson(descriptor);
}
Also used : ServiceDescriptorRestRep(com.emc.vipr.model.catalog.ServiceDescriptorRestRep) CatalogServiceFieldRestRep(com.emc.vipr.model.catalog.CatalogServiceFieldRestRep) CatalogServiceFieldRestRep(com.emc.vipr.model.catalog.CatalogServiceFieldRestRep) ServiceFieldRestRep(com.emc.vipr.model.catalog.ServiceFieldRestRep) CatalogServiceRestRep(com.emc.vipr.model.catalog.CatalogServiceRestRep)

Example 4 with CatalogServiceFieldRestRep

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

the class CatalogServiceMapper method map.

public static CatalogServiceRestRep map(CatalogService from, ServiceDescriptor descriptor, List<CatalogServiceField> catalogServiceFields) {
    if (from == null) {
        return null;
    }
    CatalogServiceRestRep to = new CatalogServiceRestRep();
    mapDataObjectFields(from, to);
    if (from.getCatalogCategoryId() != null) {
        to.setCatalogCategory(toRelatedResource(ResourceTypeEnum.CATALOG_CATEGORY, from.getCatalogCategoryId().getURI()));
    }
    if (from.getDefaultExecutionWindowId() != null) {
        to.setDefaultExecutionWindow(toRelatedResource(ResourceTypeEnum.EXECUTION_WINDOW, from.getDefaultExecutionWindowId().getURI()));
    }
    if (from.getApprovalRequired() != null) {
        to.setApprovalRequired(from.getApprovalRequired());
    }
    if (from.getExecutionWindowRequired() != null) {
        to.setExecutionWindowRequired(from.getExecutionWindowRequired());
    }
    to.setBaseService(from.getBaseService());
    to.setDescription(from.getDescription());
    to.setImage(from.getImage());
    to.setMaxSize(from.getMaxSize());
    to.setTitle(from.getTitle());
    to.setSortedIndex(from.getSortedIndex());
    if (descriptor != null) {
        to.setServiceDescriptor(ServiceDescriptorMapper.map(descriptor));
    }
    if (catalogServiceFields != null) {
        for (CatalogServiceField catalogServiceField : catalogServiceFields) {
            CatalogServiceFieldRestRep catalogServiceFieldRestRep = new CatalogServiceFieldRestRep();
            mapDataObjectFields(catalogServiceField, catalogServiceFieldRestRep);
            catalogServiceFieldRestRep.setOverride(catalogServiceField.getOverride());
            catalogServiceFieldRestRep.setValue(catalogServiceField.getValue());
            catalogServiceFieldRestRep.setSortedIndex(catalogServiceField.getSortedIndex());
            to.getCatalogServiceFields().add(catalogServiceFieldRestRep);
        }
    }
    if (from.getRecurringAllowed() != null) {
        to.setRecurringAllowed(from.getRecurringAllowed());
    }
    return to;
}
Also used : CatalogServiceFieldRestRep(com.emc.vipr.model.catalog.CatalogServiceFieldRestRep) CatalogServiceField(com.emc.storageos.db.client.model.uimodels.CatalogServiceField) CatalogServiceRestRep(com.emc.vipr.model.catalog.CatalogServiceRestRep)

Aggregations

CatalogServiceFieldRestRep (com.emc.vipr.model.catalog.CatalogServiceFieldRestRep)4 CatalogServiceRestRep (com.emc.vipr.model.catalog.CatalogServiceRestRep)3 ServiceDescriptorRestRep (com.emc.vipr.model.catalog.ServiceDescriptorRestRep)2 ServiceFieldRestRep (com.emc.vipr.model.catalog.ServiceFieldRestRep)2 CatalogServiceField (com.emc.storageos.db.client.model.uimodels.CatalogServiceField)1 AssetOption (com.emc.vipr.model.catalog.AssetOption)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Gson (com.google.gson.Gson)1 HashMap (java.util.HashMap)1 AssetFieldDescriptor (util.ServiceFormUtils.AssetFieldDescriptor)1