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