@Override public void setAttributeValue(final String attrName, final String attrValue) throws JSONException { if (StringUtils.isEmpty(attrName)) throw new IllegalArgumentException("Please enter attribute name!"); final DynamicEnvironment dynamicEnvironment = (DynamicEnvironment) ConfigurationManager.INSTANCE.getDefaultEnvironment(); final Artefact artefact = ConfigurationRepository.INSTANCE.getArtefact(configName); if (artefact == null) throw new IllegalArgumentException("No such artefact: " + configName); List<? extends ParsedAttribute<?>> attList = JsonParser.parse(attrName, attrValue, dynamicEnvironment); if (attList == null || attList.isEmpty()) throw new JSONException("Nothing to parse. Please fill out attribute name and value."); ParsedAttribute<?> parsedAttribute = attList.get(0); artefact.addAttributeValue(attrName, parsedAttribute.getValue(), dynamicEnvironment); ConfigurationRepository.INSTANCE.updateArtefact(artefact); }
@Override public String showContent() { final Artefact artefact = ConfigurationRepository.INSTANCE.getArtefact(configName); if (artefact == null) throw new IllegalArgumentException("No such artefact: " + configName); Map<Environment, Map<String, Object>> contentMap = artefact.getContent(); StringBuilder resultContent = new StringBuilder(); resultContent.append("{\n"); for (Map.Entry<Environment, Map<String, Object>> environmentMapEntry : contentMap.entrySet()) { String env = environmentMapEntry.getKey().expandedStringForm(); resultContent.append(" ").append(env.isEmpty() ? "" : env + ": ").append("{\n"); for (Map.Entry<String, Object> stringObjectEntry : environmentMapEntry.getValue().entrySet()) resultContent .append(" ") .append(stringObjectEntry.getKey()) .append(" : ") .append(stringObjectEntry.getValue()) .append(",\n"); resultContent.append(" },\n"); } resultContent.append("}"); return resultContent.toString(); }