Search in sources :

Example 11 with CatalogServiceRestRep

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

the class Notifications method getNotifications.

@Util
public static List<Notification> getNotifications() {
    ViPRCatalogClient2 catalog = getCatalogClient();
    List<Notification> notifications = Lists.newArrayList();
    List<ApprovalRestRep> approvals = catalog.approvals().search().byStatus(ApprovalRestRep.PENDING).run();
    for (ApprovalRestRep approval : approvals) {
        if (approval.getOrder() != null) {
            OrderRestRep order = getOrder(approval.getOrder());
            if (order != null) {
                CatalogServiceRestRep service = getCatalogService(order.getCatalogService());
                Notification notification = new Notification();
                notification.id = approval.getId().toString();
                notification.orderId = order.getId().toString();
                if (service != null) {
                    notification.image = service.getImage();
                    notification.message = MessagesUtils.get("notification.approvalPending", service.getTitle(), order.getSubmittedBy());
                }
                notification.lastUpdated = approval.getDateActioned() != null ? approval.getDateActioned() : approval.getCreationTime().getTime();
                notifications.add(notification);
            }
        }
    }
    return notifications;
}
Also used : ApprovalRestRep(com.emc.vipr.model.catalog.ApprovalRestRep) OrderRestRep(com.emc.vipr.model.catalog.OrderRestRep) ViPRCatalogClient2(com.emc.vipr.client.ViPRCatalogClient2) CatalogServiceRestRep(com.emc.vipr.model.catalog.CatalogServiceRestRep) Util(play.mvc.Util)

Example 12 with CatalogServiceRestRep

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

the class AssetOptionsApi method dependencies.

public static void dependencies(String asset, String service) {
    // The 'service' may be the baseService or a service ID
    ServiceDescriptorRestRep descriptor;
    if (StringUtils.isEmpty(service)) {
        error(Messages.get("AssetOptionsApi.serviceParameterIsRequired"));
    }
    if (service.startsWith("urn:")) {
        CatalogServiceRestRep catalogService = CatalogServiceUtils.getCatalogService(uri(service));
        descriptor = catalogService.getServiceDescriptor();
    } else {
        descriptor = ServiceDescriptorUtils.getDescriptor(service);
    }
    Set<String> allAssetTypes = ServiceDescriptorUtils.getAllAssetTypes(descriptor);
    List<String> dependencies = calculateAssetDependencies(cleanAssetType(asset), allAssetTypes);
    List<Reference> references = Lists.newArrayList();
    for (String dependency : dependencies) {
        references.add(newAssetOptionsReference(dependency));
    }
    renderApi(references);
}
Also used : ServiceDescriptorRestRep(com.emc.vipr.model.catalog.ServiceDescriptorRestRep) Reference(com.emc.vipr.model.catalog.Reference) ApiMapperUtils.newAssetOptionsReference(util.api.ApiMapperUtils.newAssetOptionsReference) CatalogServiceRestRep(com.emc.vipr.model.catalog.CatalogServiceRestRep)

Example 13 with CatalogServiceRestRep

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

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

the class Orders method createAndValidateOrder.

@Util
public static OrderCreateParam createAndValidateOrder(String serviceId) {
    CatalogServiceRestRep service = CatalogServiceUtils.getCatalogService(uri(serviceId));
    ServiceDescriptorRestRep descriptor = service.getServiceDescriptor();
    if (descriptor == 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 ");
    }
    // Filter out actual Service Parameters
    Map<String, String> parameters = parseParameters(service, descriptor);
    if (Validation.hasErrors()) {
        Validation.keep();
        Common.flashParamsExcept("json", "body");
        Services.showForm(serviceId);
    }
    return createOrder(service, descriptor, parameters);
}
Also used : ServiceDescriptorRestRep(com.emc.vipr.model.catalog.ServiceDescriptorRestRep) CatalogServiceRestRep(com.emc.vipr.model.catalog.CatalogServiceRestRep) BourneUtil(util.BourneUtil) TaskUtil(com.emc.vipr.client.core.impl.TaskUtil) Util(play.mvc.Util)

Example 15 with CatalogServiceRestRep

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

the class ServiceCatalog method createCategory.

private static CategoryDef createCategory(CatalogCategoryRestRep category, String path) {
    CategoryDef def = new CategoryDef();
    def.id = category.getId().toString();
    def.name = category.getName();
    def.title = category.getTitle();
    def.description = category.getDescription();
    def.image = category.getImage();
    def.parentId = getParentId(category.getCatalogCategory());
    def.path = getPath(path, def.name);
    List<CatalogServiceRestRep> catalogServices = CatalogServiceUtils.getCatalogServices(category);
    for (CatalogServiceRestRep catalogService : catalogServices) {
        def.services.add(createService(catalogService, def.path));
    }
    List<CatalogCategoryRestRep> subCategories = CatalogCategoryUtils.getCatalogCategories(category);
    for (CatalogCategoryRestRep subCategory : subCategories) {
        def.categories.add(createCategory(subCategory, def.path));
    }
    return def;
}
Also used : CatalogServiceRestRep(com.emc.vipr.model.catalog.CatalogServiceRestRep) CatalogCategoryRestRep(com.emc.vipr.model.catalog.CatalogCategoryRestRep)

Aggregations

CatalogServiceRestRep (com.emc.vipr.model.catalog.CatalogServiceRestRep)29 ServiceDescriptorRestRep (com.emc.vipr.model.catalog.ServiceDescriptorRestRep)7 CatalogCategoryRestRep (com.emc.vipr.model.catalog.CatalogCategoryRestRep)6 ViPRCatalogClient2 (com.emc.vipr.client.ViPRCatalogClient2)4 ApprovalRestRep (com.emc.vipr.model.catalog.ApprovalRestRep)3 CatalogServiceFieldRestRep (com.emc.vipr.model.catalog.CatalogServiceFieldRestRep)3 OrderRestRep (com.emc.vipr.model.catalog.OrderRestRep)3 ServiceFieldRestRep (com.emc.vipr.model.catalog.ServiceFieldRestRep)3 Util (play.mvc.Util)3 CatalogServiceField (com.emc.storageos.db.client.model.uimodels.CatalogServiceField)2 DataObjectRestRep (com.emc.storageos.model.DataObjectRestRep)2 TaskUtil (com.emc.vipr.client.core.impl.TaskUtil)2 Parameter (com.emc.vipr.model.catalog.Parameter)2 URI (java.net.URI)2 HashMap (java.util.HashMap)2 DateTime (org.joda.time.DateTime)2 BourneUtil (util.BourneUtil)2 WorkflowServiceDescriptor (com.emc.sa.catalog.WorkflowServiceDescriptor)1 ServiceDescriptor (com.emc.sa.descriptor.ServiceDescriptor)1 CatalogService (com.emc.storageos.db.client.model.uimodels.CatalogService)1