Search in sources :

Example 1 with ScopeParam

use of com.emc.storageos.model.customconfig.ScopeParam in project coprhd-controller by CoprHD.

the class CustomConfigService method createCustomConfig.

/**
 * Creates config.
 *
 * @param createParam create parameters
 * @brief Create config
 * @return CustomConfigRestRep
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public CustomConfigRestRep createCustomConfig(CustomConfigCreateParam createParam) {
    String configType = createParam.getConfigType();
    String theVal = createParam.getValue();
    ArgValidator.checkFieldNotEmpty(configType, CONFIG_TYPE);
    ArgValidator.checkFieldNotEmpty(theVal, VALUE);
    ScopeParam scopeParam = createParam.getScope();
    ArgValidator.checkFieldNotNull(scopeParam, SCOPE);
    StringMap scopeMap = new StringMap();
    scopeMap.put(scopeParam.getType(), scopeParam.getValue());
    customConfigHandler.validate(configType, scopeMap, theVal, true);
    String label = CustomConfigHandler.constructConfigName(configType, scopeMap);
    CustomConfig config = new CustomConfig();
    config.setId(URIUtil.createId(CustomConfig.class));
    config.setConfigType(configType);
    config.setScope(scopeMap);
    config.setLabel(label);
    config.setValue(theVal);
    config.setRegistered(createParam.getRegistered());
    config.setSystemDefault(false);
    _dbClient.createObject(config);
    auditOp(OperationTypeEnum.CREATE_CONFIG, true, null, config.getId().toString(), config.getLabel(), config.getScope());
    return DbObjectMapper.map(config);
}
Also used : CustomConfig(com.emc.storageos.db.client.model.CustomConfig) MapCustomConfig(com.emc.storageos.api.mapper.functions.MapCustomConfig) StringMap(com.emc.storageos.db.client.model.StringMap) ConfigTypeScopeParam(com.emc.storageos.model.customconfig.ConfigTypeScopeParam) ScopeParam(com.emc.storageos.model.customconfig.ScopeParam) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 2 with ScopeParam

use of com.emc.storageos.model.customconfig.ScopeParam in project coprhd-controller by CoprHD.

the class CustomConfigService method getCustomConfigPreviewValue.

/**
 * Get a config preview value.
 *
 * @param param create parameters
 * @brief Get config preview value
 * @return preview value
 */
@POST
@Path("/preview")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public CustomConfigPreviewRep getCustomConfigPreviewValue(CustomConfigPreviewParam param) {
    String configType = param.getConfigType();
    String theVal = param.getValue();
    ArgValidator.checkFieldNotEmpty(configType, CONFIG_TYPE);
    ArgValidator.checkFieldNotEmpty(theVal, VALUE);
    ScopeParam scopeParm = param.getScope();
    StringMap scope = null;
    if (scopeParm != null) {
        scope = new StringMap();
        scope.put(scopeParm.getType(), scopeParm.getValue());
    }
    List<PreviewVariableParam> variables = param.getPreviewVariables();
    Map<String, String> variableValues = null;
    if (variables != null && !variables.isEmpty()) {
        variableValues = new HashMap<String, String>();
        for (PreviewVariableParam variable : variables) {
            variableValues.put(variable.getVariableName(), variable.getValue());
        }
    }
    String result = customConfigHandler.getCustomConfigPreviewValue(configType, theVal, scope, variableValues);
    CustomConfigPreviewRep preview = new CustomConfigPreviewRep(result);
    return preview;
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) CustomConfigPreviewRep(com.emc.storageos.model.customconfig.CustomConfigPreviewRep) ConfigTypeScopeParam(com.emc.storageos.model.customconfig.ConfigTypeScopeParam) ScopeParam(com.emc.storageos.model.customconfig.ScopeParam) PreviewVariableParam(com.emc.storageos.model.customconfig.PreviewVariableParam) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 3 with ScopeParam

use of com.emc.storageos.model.customconfig.ScopeParam in project coprhd-controller by CoprHD.

the class DbObjectMapper method map.

public static CustomConfigRestRep map(CustomConfig from) {
    if (from == null) {
        return null;
    }
    CustomConfigRestRep to = new CustomConfigRestRep();
    to.setLink(new RestLinkRep("self", RestLinkFactory.newLink(from)));
    // build the config type Link
    String service = ResourceTypeEnum.CONFIG_TYPE.getService();
    StringBuilder build = (new StringBuilder(service)).append('/').append(from.getConfigType());
    try {
        RelatedConfigTypeRep type = new RelatedConfigTypeRep();
        type.setConfigName(from.getConfigType());
        type.setSelfLink(new RestLinkRep("self", new URI(build.toString())));
        to.setConfigType(type);
    } catch (URISyntaxException e) {
    // it should not happen
    }
    to.setId(from.getId());
    to.setName(from.getLabel());
    StringMap scopeMap = from.getScope();
    ScopeParam scopeParm = new ScopeParam();
    for (Map.Entry<String, String> entry : scopeMap.entrySet()) {
        scopeParm.setType(entry.getKey());
        scopeParm.setValue(entry.getValue());
    }
    to.setScope(scopeParm);
    to.setValue(from.getValue());
    to.setRegistered(from.getRegistered());
    to.setSystemDefault(from.getSystemDefault());
    return to;
}
Also used : RelatedConfigTypeRep(com.emc.storageos.model.customconfig.RelatedConfigTypeRep) StringMap(com.emc.storageos.db.client.model.StringMap) CustomConfigRestRep(com.emc.storageos.model.customconfig.CustomConfigRestRep) RestLinkRep(com.emc.storageos.model.RestLinkRep) ScopeParam(com.emc.storageos.model.customconfig.ScopeParam) URISyntaxException(java.net.URISyntaxException) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Map(java.util.Map) StringMap(com.emc.storageos.db.client.model.StringMap)

Example 4 with ScopeParam

use of com.emc.storageos.model.customconfig.ScopeParam in project coprhd-controller by CoprHD.

the class CustomConfigUtils method createCustomConfig.

public static CustomConfigRestRep createCustomConfig(String configType, String scopeType, String scopeValue, String value) {
    ScopeParam scope = new ScopeParam();
    scope.setType(scopeType);
    scope.setValue(scopeValue);
    CustomConfigCreateParam param = new CustomConfigCreateParam();
    param.setConfigType(configType);
    param.setScope(scope);
    param.setValue(value);
    return getViprClient().customConfigs().createCustomConfig(param);
}
Also used : ScopeParam(com.emc.storageos.model.customconfig.ScopeParam) CustomConfigCreateParam(com.emc.storageos.model.customconfig.CustomConfigCreateParam)

Example 5 with ScopeParam

use of com.emc.storageos.model.customconfig.ScopeParam in project coprhd-controller by CoprHD.

the class CustomConfigUtils method generatePreview.

public static CustomConfigPreviewRep generatePreview(String configType, String scopeType, String scopeValue, String value) {
    CustomConfigPreviewParam param = new CustomConfigPreviewParam();
    param.setConfigType(configType);
    param.setScope(new ScopeParam(scopeType, scopeValue));
    param.setValue(value);
    return getViprClient().customConfigs().getCustomConfigPreviewValue(param);
}
Also used : ScopeParam(com.emc.storageos.model.customconfig.ScopeParam) CustomConfigPreviewParam(com.emc.storageos.model.customconfig.CustomConfigPreviewParam)

Aggregations

ScopeParam (com.emc.storageos.model.customconfig.ScopeParam)6 StringMap (com.emc.storageos.db.client.model.StringMap)3 ConfigTypeScopeParam (com.emc.storageos.model.customconfig.ConfigTypeScopeParam)3 CustomConfigRestRep (com.emc.storageos.model.customconfig.CustomConfigRestRep)2 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Produces (javax.ws.rs.Produces)2 MapCustomConfig (com.emc.storageos.api.mapper.functions.MapCustomConfig)1 CustomConfig (com.emc.storageos.db.client.model.CustomConfig)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 RestLinkRep (com.emc.storageos.model.RestLinkRep)1 CustomConfigCreateParam (com.emc.storageos.model.customconfig.CustomConfigCreateParam)1 CustomConfigPreviewParam (com.emc.storageos.model.customconfig.CustomConfigPreviewParam)1 CustomConfigPreviewRep (com.emc.storageos.model.customconfig.CustomConfigPreviewRep)1 PreviewVariableParam (com.emc.storageos.model.customconfig.PreviewVariableParam)1 RelatedConfigTypeRep (com.emc.storageos.model.customconfig.RelatedConfigTypeRep)1 ServiceErrorException (com.emc.vipr.client.exceptions.ServiceErrorException)1 FlashException (controllers.util.FlashException)1 URI (java.net.URI)1