Project { public final void updateConfig(ProjectConfig update) throws ServerException, ValueStorageException, ProjectTypeConstraintException, InvalidValueException { final ProjectJson projectJson = new ProjectJson(); ProjectTypes types = new ProjectTypes(update.getTypeId(), update.getMixinTypes()); types.removeTransient(); projectJson.setType(types.primary.getId()); projectJson.setBuilders(update.getBuilders()); projectJson.setRunners(update.getRunners()); projectJson.setDescription(update.getDescription()); ArrayList<String> ms = new ArrayList<>(); ms.addAll(types.mixins.keySet()); projectJson.setMixinTypes(ms); HashMap<String, AttributeValue> checkVariables = new HashMap<>(); for (String attributeName : update.getAttributes().keySet()) { AttributeValue attributeValue = update.getAttributes().get(attributeName); Attribute definition = null; for (ProjectType t : types.all.values()) { definition = t.getAttribute(attributeName); if (definition != null) break; } if (definition != null && definition.isVariable()) { Variable var = (Variable)definition; if (attributeValue == null && var.isRequired()) { throw new ProjectTypeConstraintException("Required attribute value is initialized with null value " + var.getId()); } if (attributeValue != null) { final ValueProviderFactory valueProviderFactory = var.getValueProviderFactory(); if (valueProviderFactory != null) { valueProviderFactory.newInstance(baseFolder).setValues(var.getName(), attributeValue.getList()); } if (valueProviderFactory == null) { projectJson.getAttributes().put(definition.getName(), attributeValue.getList()); } } checkVariables.put(attributeName, attributeValue); } } for (ProjectType t : types.all.values()) { for (Attribute attr : t.getAttributes()) { if (attr.isVariable()) { if (!checkVariables.containsKey(attr.getName()) && attr.isRequired()) { throw new ProjectTypeConstraintException("Required attribute value is initialized with null value " + attr.getId()); } } else { projectJson.getAttributes().put(attr.getName(), attr.getValue().getList()); } } } if (projectJson.getBuilders().getDefault() == null) projectJson.getBuilders().setDefault(types.primary.getDefaultBuilder()); if (projectJson.getRunners().getDefault() == null) projectJson.getRunners().setDefault(types.primary.getDefaultRunner()); projectJson.save(this); } Project(FolderEntry baseFolder, ProjectManager manager); String getWorkspace(); String getName(); String getPath(); FolderEntry getBaseFolder(); long getCreationDate(); long getModificationDate(); String getContentRoot(); ProjectMisc getMisc(); void saveMisc(ProjectMisc misc); static Path getAbsoluteModulePath(String modulePath, Project parentProject); ProjectConfig getConfig(); final void updateConfig(ProjectConfig update); String getVisibility(); void setVisibility(String projectVisibility); List<AccessControlEntry> getPermissions(); void setPermissions(List<AccessControlEntry> acl); VirtualFileEntry getItem(String path); Modules getModules();  }
@Test public void testUpdateProjectDescriptor() throws Exception { Project myProject = pm.getProject("my_ws", "my_project"); Map<String, List<String>> attributes = new HashMap<>(2); attributes.put("my_property_1", Arrays.asList("value_1", "value_2")); ProjectJson projectJson = new ProjectJson("my_project_type", attributes, null, null, "test project"); projectJson.save(myProject); Map <String, AttributeValue> attrs = new HashMap<>(); attrs.put("calculated_attribute", new AttributeValue("updated calculated_attribute")); attrs.put("my_property_1", new AttributeValue("updated value 1")); attrs.put("new_my_property_2", new AttributeValue("new value 2")); ProjectConfig myConfig = new ProjectConfig("descr", "my_project_type", attrs, null, null, null); myProject.updateConfig(myConfig); projectJson = ProjectJson.load(myProject); Assert.assertEquals(projectJson.getType(), "my_project_type"); Assert.assertEquals(calculateAttributeValueHolder, Arrays.asList("updated calculated_attribute")); Map<String, List<String>> pm = projectJson.getAttributes(); Assert.assertEquals(pm.size(), 1); Assert.assertEquals(pm.get("my_property_1"), Arrays.asList("updated value 1")); }