use of org.eclipse.che.api.core.model.project.type.Attribute in project che by eclipse.
the class ProjectTypeDef method resolveSources.
public ProjectTypeResolution resolveSources(FolderEntry projectFolder) {
Map<String, Value> matchAttrs = new HashMap<>();
for (Map.Entry<String, Attribute> entry : attributes.entrySet()) {
Attribute attr = entry.getValue();
String name = entry.getKey();
if (attr.isVariable()) {
Variable var = (Variable) attr;
ValueProviderFactory factory = var.getValueProviderFactory();
if (factory != null) {
Value value;
String errorMessage = "";
try {
value = new AttributeValue(factory.newInstance(projectFolder).getValues(name));
} catch (ValueStorageException e) {
value = null;
errorMessage = e.getLocalizedMessage();
}
if (value == null || value.isEmpty()) {
if (var.isRequired()) {
// this PT is not match
errorMessage = errorMessage.isEmpty() ? format("Value for required attribute %s is not initialized", name) : errorMessage;
return new DefaultResolution(id, errorMessage);
}
} else {
// add one more matched attribute
matchAttrs.put(name, value);
}
}
}
}
return new DefaultResolution(id, matchAttrs, true);
}
use of org.eclipse.che.api.core.model.project.type.Attribute in project che by eclipse.
the class ProjectTypeRegistry method initRecursively.
/**
* initializes all the attributes defined in myType and its ancestors recursively
*
* @param myType
* @param typeId
* temporary type for recursive (started with initial type)
* @throws ProjectTypeConstraintException
*/
private final void initRecursively(ProjectTypeDef myType, String typeId) throws ProjectTypeConstraintException {
ProjectTypeDef type = validatedData.get(typeId);
for (String superTypeId : type.getParents()) {
myType.addAncestor(superTypeId);
ProjectTypeDef supertype = validatedData.get(superTypeId);
for (Attribute attr : supertype.getAttributes()) {
// check attribute names
for (Attribute attr2 : myType.getAttributes()) {
if (attr.getName().equals(attr2.getName()) && !attr.getProjectType().equals(attr2.getProjectType())) {
throw new ProjectTypeConstraintException("Attribute name conflict. Project type " + myType.getId() + " could not be registered as attribute declaration " + attr.getName() + " is duplicated in its ancestor(s).");
}
}
myType.addAttributeDefinition(attr);
}
initRecursively(myType, superTypeId);
}
}
use of org.eclipse.che.api.core.model.project.type.Attribute in project che by eclipse.
the class ProjectTypes method reset.
/**
* Reset project types and atrributes after initialization
* in case when some attributes are not valid
* (for instance required attributes are not initialized)
*
* @param attributesToDel - invalid attributes
*/
void reset(Set<Attribute> attributesToDel) {
Set<String> ptsToDel = new HashSet<>();
for (Attribute attr : attributesToDel) {
ptsToDel.add(attr.getProjectType());
}
Set<String> attrNamesToDel = new HashSet<>();
for (String pt : ptsToDel) {
ProjectTypeDef typeDef = all.get(pt);
for (Attribute attrDef : typeDef.getAttributes()) {
attrNamesToDel.add(attrDef.getName());
}
}
// remove project types
for (String typeId : ptsToDel) {
this.all.remove(typeId);
if (this.primary.getId().equals(typeId)) {
this.primary = ProjectTypeRegistry.BASE_TYPE;
this.all.put(ProjectTypeRegistry.BASE_TYPE.getId(), ProjectTypeRegistry.BASE_TYPE);
} else {
mixins.remove(typeId);
}
}
// remove attributes
for (String attr : attrNamesToDel) {
this.attributeDefs.remove(attr);
}
}
use of org.eclipse.che.api.core.model.project.type.Attribute in project che by eclipse.
the class ProjectTypes method addTransient.
void addTransient(FolderEntry projectFolder) {
for (ProjectTypeDef pt : projectTypeRegistry.getProjectTypes()) {
// NOTE: Only mixable types allowed
if (pt.isMixable() && !pt.isPersisted() && pt.resolveSources(projectFolder).matched()) {
all.put(pt.getId(), pt);
mixins.put(pt.getId(), pt);
for (Attribute attr : pt.getAttributes()) {
final String attrName = attr.getName();
if (attributeDefs.containsKey(attrName)) {
problems.add(new Problem(ATTRIBUTE_NAME_PROBLEM, format("Attribute name conflict. Duplicated attributes detected for %s. " + "Attribute %s declared in %s already declared in %s. Skipped.", projectPath, attrName, pt.getId(), attributeDefs.get(attrName).getProjectType())));
}
attributeDefs.put(attrName, attr);
}
}
}
}
Aggregations