public static Builder builder(FeatureParameterSpec param) { Builder builder = new Builder(param.getName()); builder.setDefaultValue(param.getDefaultValue()); if (param.isFeatureId()) { builder.setFeatureId(); } if(param.isNillable()) { builder.setNillable(); } builder.setType(param.getType()); return builder; }
public FeatureParameterSpec build() throws ProvisioningDescriptionException { return new FeatureParameterSpec(this); } }
final FeatureParameterSpec pSpec = fSpec.getParam(paramName); if(!actualParams.remove(paramName)) { if(pSpec.isNillable() && pSpec.hasDefaultValue() && !Constants.GLN_UNDEFINED.equals(pSpec.getDefaultValue())) { config.unsetParam(paramName); final String originalValue = original.getConfigParam(paramName); if(actualValue != null) { if(!pSpec.isFeatureId() && !actualValue.equals(originalValue) && !actualValue.equals(pSpec.getDefaultValue())) { config.setParam(paramName, actualValue); if(pSpec.hasDefaultValue() && !Constants.GLN_UNDEFINED.equals(pSpec.getDefaultValue())) { config.unsetParam(paramName);
ResolvedFeatureParam(FeatureParameterSpec spec, FeatureParameterType type) throws ProvisioningException { this.spec = spec; this.type = type; if(spec.hasDefaultValue()) { defaultValue = type.fromString(spec.getDefaultValue()); } else { defaultValue = type.getDefaultValue(); } if(spec.isFeatureId() && type.isCollection()) { throw new ProvisioningException("Feature ID parameter cannot be of a collection type"); } } }
@Override protected List<DynamicOption> getDynamicOptions(State state) throws Exception { if (state == null) { return Collections.emptyList(); } List<DynamicOption> options = new ArrayList<>(); for (Entry<String, FeatureParameterSpec> entry : getSpec(state, getId()).getSpec().getParams().entrySet()) { DynamicOption dyn = new DynamicOption(entry.getKey(), !entry.getValue().isNillable() && !entry.getValue().hasDefaultValue()); String defValue = entry.getValue().getDefaultValue(); if (defValue != null) { dyn.setDefaultValue(defValue.toString()); } options.add(dyn); } return options; }
for (Map.Entry<String, String> mapping : refSpec.getMappedParams().entrySet()) { final FeatureParameterSpec param = xmlSpec.getParam(mapping.getKey()); if(!param.isFeatureId()) { continue; String configValue = params.get(idParamSpec.getName()); if(configValue != null) { final Object childValue = paramFromString(idParamSpec.getName(), configValue); final Object idValue = resolvedParams.put(idParamSpec.getName(), childValue); if(idValue != null && !idValue.equals(childValue)) { throw new ProvisioningDescriptionException(Errors.idParamForeignKeyInitConflict(id, idParamSpec.getName(), childValue, idValue)); if(resolvedParams.containsKey(idParamSpec.getName())) { continue; final Object childValue = getResolvedParam(idParamSpec.getName()).defaultValue; if(childValue == null) { throw new ProvisioningDescriptionException(Errors.nonNillableParameterIsNull(id, idParamSpec.getName())); resolvedParams.put(idParamSpec.getName(), childValue); final Object parentValue = parentId.params.get(idParamSpec.getName()); String configValue = params.get(idParamSpec.getName()); if(configValue != null) { final Object childValue = paramFromString(idParamSpec.getName(), configValue); if(parentValue != null && !parentValue.equals(childValue)) { throw new ProvisioningDescriptionException(Errors.idParamForeignKeyInitConflict(id, idParamSpec.getName(), childValue, parentValue)); resolvedParams.put(idParamSpec.getName(), childValue);
private ResolvedFeatureParam resolveParamSpec(FeatureParameterSpec paramSpec, ParameterTypeProvider typeProvider) throws ProvisioningException { final FeatureParameterType type; try { type = typeProvider.getType(id.producer, paramSpec.getType()); } catch(ParameterTypeNotFoundException e) { throw new ProvisioningException(Errors.failedToResolveParameter(id, paramSpec.getName()), e); } return new ResolvedFeatureParam(paramSpec, type); }
FeatureParameterSpec p = spec.getSpec().getParams().get(opt); String value = options.get(opt); if (p.isFeatureId()) { if (!Constants.GLN_UNDEFINED.equals(value)) { ids.put(opt, value); } else if (!value.equals(p.getDefaultValue())) { params.put(opt, value);
private Object resolveIdParamValue(Map<String, String> params, final FeatureParameterSpec param) throws ProvisioningException { final ResolvedFeatureParam resolvedParam = getResolvedParam(param.getName()); final String strValue = params.get(param.getName()); if(strValue == null) { final Object value = resolvedParam.defaultValue; if (value == null) { throw new ProvisioningDescriptionException(Errors.nonNillableParameterIsNull(id, param.getName())); } return value; } return resolvedParam.type.fromString(strValue); }
void attachSpecInfo(FeatureSpecInfo specInfo) { this.specInfo = specInfo; if (featureConfig != null) { for (Map.Entry<String, Object> p : feature.getResolvedParams().entrySet()) { if (!specInfo.getSpec().getParams().get(p.getKey()).isFeatureId()) { featureConfig.setParam(p.getKey(), p.getValue().toString()); } } } } public FeatureId getFeatureId() {
void validate() throws ProvisioningDescriptionException { for(Map.Entry<String, ResolvedFeatureParam> entry : spec.getResolvedParams().entrySet()) { final ResolvedFeatureParam param = entry.getValue(); if(params.containsKey(entry.getKey())) { continue; } if(param.defaultValue == null || unsetParams.contains(entry.getKey())) { if(param.spec.isNillable()) { continue; } throw new ProvisioningDescriptionException(Errors.nonNillableParameterIsNull(this, entry.getKey())); } params.put(entry.getKey(), param.defaultValue); } }
private FeatureParameterSpec parseParameter(XMLExtendedStreamReader reader) throws XMLStreamException { final FeatureParameterSpec.Builder builder = FeatureParameterSpec.builder(); for (int i = 0; i < reader.getAttributeCount(); i++) { final Attribute attribute = Attribute.of(reader.getAttributeName(i));
if(!child && (resolvedParam.spec.isFeatureId() && targetSpec.getSpec().getParam(refParamName).isFeatureId())) { child = true; final String paramName = targetIdParam.getName(); final String refParamName = paramName; if(!child && resolvedParam.spec.isFeatureId()) { child = true;
ResolvedFeatureId resolveFeatureId(Map<String, String> params) throws ProvisioningException { if(!xmlSpec.hasId()) { return null; } final List<FeatureParameterSpec> idSpecs = xmlSpec.getIdParams(); if(idSpecs.size() == 1) { final FeatureParameterSpec idSpec = idSpecs.get(0); return new ResolvedFeatureId(id, Collections.singletonMap(idSpec.getName(), resolveIdParamValue(params, idSpec))); } final Map<String, Object> resolvedParams = new HashMap<>(idSpecs.size()); for(FeatureParameterSpec param : idSpecs) { resolvedParams.put(param.getName(), resolveIdParamValue(params, param)); } return new ResolvedFeatureId(id, resolvedParams); }
if (!params.isEmpty()) { for (Map.Entry<String, String> param : params.entrySet()) { if(xmlSpec.getParam(param.getKey()).isFeatureId()) { continue; if (refSpec.hasMappedParams()) { for (Map.Entry<String, String> mapping : refSpec.getMappedParams().entrySet()) { if (xmlSpec.getParam(mapping.getKey()).isFeatureId()) { continue; if (xmlSpec.getParam(parentEntry.getKey()).isFeatureId()) { continue;
for (FeatureParameterSpec param : idparams) { StringBuilder builder = new StringBuilder(); builder.append(tab + param.getName()).append(Config.getLineSeparator()); builder.append(tab + tab + "description : " + "no description available").append(Config.getLineSeparator()); builder.append(tab + tab + "type : " + param.getType()).append(Config.getLineSeparator()); builder.append(tab + tab + "default-value: " + param.getDefaultValue()).append(Config.getLineSeparator()); builder.append(tab + tab + "nillable : " + param.isNillable()).append(Config.getLineSeparator()); session.print(builder.toString()); for (Entry<String, FeatureParameterSpec> entry : params.entrySet()) { FeatureParameterSpec param = entry.getValue(); if (!param.isFeatureId()) { StringBuilder builder = new StringBuilder(); builder.append(tab + param.getName()).append(Config.getLineSeparator()); builder.append(tab + tab + "description : " + "no description available").append(Config.getLineSeparator()); builder.append(tab + tab + "type : " + param.getType()).append(Config.getLineSeparator()); builder.append(tab + tab + "default-value: " + param.getDefaultValue()).append(Config.getLineSeparator()); builder.append(tab + tab + "nillable : " + param.isNillable()).append(Config.getLineSeparator()); session.println(builder.toString());
for(Map.Entry<String, FeatureParameterSpec> entry : xmlSpec.getParams().entrySet()) { final FeatureParameterSpec param = entry.getValue(); resolvedParamSpecs = CollectionUtils.put(resolvedParamSpecs, param.getName(), resolveParamSpec(param, typeProvider));
public static FeatureParameterSpec create(String name, boolean nillable) throws ProvisioningDescriptionException { return new FeatureParameterSpec(name, false, nillable, null); }
for(FeatureParameterSpec paramSpec : featureSpec.getParams().values()) { final ElementNode paramE = addElement(paramsE, Element.PARAMETER); addAttribute(paramE, Attribute.NAME, paramSpec.getName()); if(paramSpec.isFeatureId()) { addAttribute(paramE, Attribute.FEATURE_ID, TRUE); } else if(paramSpec.isNillable()) { addAttribute(paramE, Attribute.NILLABLE, TRUE); if(paramSpec.hasDefaultValue()) { addAttribute(paramE, Attribute.DEFAULT, paramSpec.getDefaultValue()); if(paramSpec.getType() != null && !Constants.BUILT_IN_TYPE_STRING.equals(paramSpec.getType())) { addAttribute(paramE, Attribute.TYPE, paramSpec.getType());
private void assertRefParamMapping(final FeatureReferenceSpec refSpec, final ResolvedFeatureSpec targetSpec) throws ProvisioningDescriptionException { if (!targetSpec.xmlSpec.hasId()) { throw new ProvisioningDescriptionException(id + " feature spec declares reference " + refSpec.getName() + " to feature spec " + targetSpec.id + " that has no ID parameters"); } if(!refSpec.hasMappedParams()) { for(FeatureParameterSpec targetIdParam : targetSpec.xmlSpec.getIdParams()) { if(!xmlSpec.hasParam(targetIdParam.getName())) { throw new ProvisioningDescriptionException(Errors.nonExistingForeignKeyParam(refSpec.getName(), id, targetIdParam.getName())); } } return; } if (targetSpec.xmlSpec.getIdParams().size() != refSpec.getParamsMapped()) { throw new ProvisioningDescriptionException("The number of foreign key parameters of reference " + refSpec.getName() + " in feature spec " + id + " does not match the number of the ID parameters of the referenced feature spec " + targetSpec.id); } for(Map.Entry<String, String> mapping : refSpec.getMappedParams().entrySet()) { if (!xmlSpec.hasParam(mapping.getKey())) { throw new ProvisioningDescriptionException(Errors.nonExistingForeignKeyParam(refSpec.getName(), id, mapping.getKey())); } if (!targetSpec.xmlSpec.hasParam(mapping.getValue())) { throw new ProvisioningDescriptionException( Errors.nonExistingForeignKeyTarget(mapping.getKey(), refSpec.getName(), id, mapping.getValue(), targetSpec.id)); } } }