Exemple #1
0
 @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);
 }
Exemple #2
0
  @Override
  public Map<String, Object> getAttributes() {
    Map<String, Object> attributeMap = new HashMap<String, Object>();
    final Environment defaultEnvironment = ConfigurationManager.INSTANCE.getDefaultEnvironment();
    final Configuration configuration =
        ConfigurationRepository.INSTANCE.getConfiguration(configName, defaultEnvironment);

    for (String attrName : configuration.getAttributeNames()) {
      Value attrValue = configuration.getAttribute(attrName);
      attributeMap.put(attrName, attrValue == null ? "" : attrValue.getRaw());
    }
    return attributeMap;
  }
Exemple #3
0
 @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();
 }