use of org.eclipse.che.api.core.model.project.type.Attribute in project che by eclipse.
the class DtoConverter method asDto.
/** Converts {@link ProjectTypeDef} to {@link ProjectTypeDto}. */
public static ProjectTypeDto asDto(ProjectTypeDef projectType) {
final List<AttributeDto> typeAttributes = new ArrayList<>();
for (Attribute attr : projectType.getAttributes()) {
ValueDto valueDto = newDto(ValueDto.class);
if (attr.getValue() != null) {
valueDto.withList(attr.getValue().getList());
}
typeAttributes.add(newDto(AttributeDto.class).withName(attr.getName()).withDescription(attr.getDescription()).withRequired(attr.isRequired()).withVariable(attr.isVariable()).withValue(valueDto));
}
return newDto(ProjectTypeDto.class).withId(projectType.getId()).withDisplayName(projectType.getDisplayName()).withPrimaryable(projectType.isPrimaryable()).withMixable(projectType.isMixable()).withParents(projectType.getParents()).withAncestors(projectType.getAncestors()).withAttributes(typeAttributes);
}
use of org.eclipse.che.api.core.model.project.type.Attribute in project che by eclipse.
the class ProjectTypeRegistry method overrideFactories.
private final void overrideFactories(ProjectTypeDef myType) throws ProjectTypeConstraintException {
for (Map.Entry<String, ValueProviderFactory> entry : myType.factoriesToOverride.entrySet()) {
Attribute old = myType.getAttribute(entry.getKey());
if (old == null || !old.isVariable()) {
throw new ProjectTypeConstraintException("Can not override Value Provider Factory. Variable not defined: " + myType.getId() + ":" + entry.getKey());
}
myType.attributes.put(old.getName(), new Variable(old.getId(), old.getName(), old.getDescription(), old.isRequired(), entry.getValue()));
}
}
use of org.eclipse.che.api.core.model.project.type.Attribute in project che by eclipse.
the class ProjectTypeRegistry method isNameValid.
/**
* Checks if incoming Project Type definition has valid ID (Pattern.compile("[^a-zA-Z0-9-_.]")
* and display name (should not be null or empty)
*
* @param type
* @return true if valid
*/
private boolean isNameValid(ProjectTypeDef type) {
boolean valid = true;
if (type.getId() == null || type.getId().isEmpty() || NAME_PATTERN.matcher(type.getId()).find()) {
LOG.error("Could not register Project Type ID is null or invalid (only Alphanumeric, dash, point and underscore allowed): " + type.getClass().getName());
valid = false;
}
if (type.getDisplayName() == null || type.getDisplayName().isEmpty()) {
LOG.error("Could not register Project Type with null or empty display name: " + type.getId());
valid = false;
}
for (Attribute attr : type.getAttributes()) {
// ID spelling (no spaces, only alphanumeric)
if (NAME_PATTERN.matcher(attr.getName()).find()) {
LOG.error("Could not register Project Type with invalid attribute Name (only Alphanumeric, dash and underscore allowed): " + attr.getClass().getName() + " ID: '" + attr.getId() + "'");
valid = false;
}
}
return valid;
}
use of org.eclipse.che.api.core.model.project.type.Attribute in project che by eclipse.
the class RegisteredProject method initAttributes.
/**
* Initialize project attributes.
* Note: the problem with {@link Problem#code} = 13 will be added when a value for some attribute is not initialized
*/
private void initAttributes() {
// we take only defined attributes, others ignored
for (Map.Entry<String, Attribute> entry : types.getAttributeDefs().entrySet()) {
final Attribute definition = entry.getValue();
final String name = entry.getKey();
AttributeValue value = new AttributeValue(config.getAttributes().get(name));
if (!definition.isVariable()) {
// constant, value always assumed as stated in definition
attributes.put(name, definition.getValue());
} else {
// variable
final Variable variable = (Variable) definition;
// value provided
if (variable.isValueProvided()) {
final ValueProvider valueProvider = variable.getValueProviderFactory().newInstance(folder);
if (folder != null) {
try {
if (!valueProvider.isSettable() || value.isEmpty()) {
// get provided value
value = new AttributeValue(valueProvider.getValues(name));
} else {
// set provided (not empty) value
valueProvider.setValues(name, value.getList());
}
} catch (ValueStorageException e) {
final Problem problem = new Problem(ATTRIBUTE_NAME_PROBLEM, format("Value for attribute %s is not initialized, caused by: %s", variable.getId(), e.getLocalizedMessage()));
this.problems.add(problem);
}
} else {
continue;
}
}
if (value.isEmpty() && variable.isRequired()) {
final Problem problem = new Problem(ATTRIBUTE_NAME_PROBLEM, "Value for required attribute is not initialized " + variable.getId());
this.problems.add(problem);
//throw new ProjectTypeConstraintException("Value for required attribute is not initialized " + variable.getId());
}
if (!value.isEmpty()) {
this.attributes.put(name, value);
}
}
}
}
use of org.eclipse.che.api.core.model.project.type.Attribute in project che by eclipse.
the class ProjectServiceTest method addMockedProjectConfigDto.
private void addMockedProjectConfigDto(org.eclipse.che.api.project.server.type.ProjectTypeDef myProjectType, String projectName) throws ForbiddenException, ServerException, NotFoundException, ConflictException {
final ProjectConfigDto testProjectConfigMock = mock(ProjectConfigDto.class);
when(testProjectConfigMock.getPath()).thenReturn("/" + projectName);
when(testProjectConfigMock.getName()).thenReturn(projectName);
when(testProjectConfigMock.getDescription()).thenReturn("my test project");
when(testProjectConfigMock.getType()).thenReturn("my_project_type");
when(testProjectConfigMock.getSource()).thenReturn(DtoFactory.getInstance().createDto(SourceStorageDto.class));
// when(testProjectConfigMock.getModules()).thenReturn(modules);
// when(testProjectConfigMock.findModule(anyString())).thenReturn(testProjectConfigMock);
Map<String, List<String>> attr = new HashMap<>();
for (Attribute attribute : myProjectType.getAttributes()) {
attr.put(attribute.getName(), attribute.getValue().getList());
}
when(testProjectConfigMock.getAttributes()).thenReturn(attr);
projects.add(testProjectConfigMock);
pm.createProject(testProjectConfigMock, null);
}
Aggregations