use of org.eclipse.sirius.components.domain.Entity in project sirius-components by eclipse-sirius.
the class DiagramDescriptionValidator method hasProperDomainType.
private boolean hasProperDomainType(DiagramElementDescription diagramElementDescription, DiagnosticChain diagnostics) {
boolean isValid = false;
ResourceSet resourceSet = diagramElementDescription.eResource().getResourceSet();
List<Entity> entities = this.getDomainEntitiesFromResourceSet(resourceSet);
List<EPackage> ePackages = this.getEPackagesFromRegistry(resourceSet.getPackageRegistry());
// $NON-NLS-1$
String domainType = Optional.ofNullable(diagramElementDescription.getDomainType()).orElse("");
isValid = entities.stream().anyMatch(entity -> this.describesEntity(domainType, entity));
if (!isValid && !domainType.isBlank()) {
// @formatter:off
isValid = ePackages.stream().map(EPackage::getEClassifiers).flatMap(Collection::stream).filter(EClass.class::isInstance).map(EClass.class::cast).anyMatch(classifier -> new DomainClassPredicate(domainType).test(classifier));
// @formatter:off
}
if (!isValid && diagnostics != null) {
// @formatter:off
BasicDiagnostic basicDiagnostic = new BasicDiagnostic(Diagnostic.ERROR, SIRIUS_COMPONENTS_EMF_PACKAGE, 0, String.format(DIAGRAM_ELEMENT_DESCRIPTION_INVALID_DOMAIN_TYPE_ERROR_MESSAGE, domainType), new Object[] { diagramElementDescription, ViewPackage.Literals.DIAGRAM_ELEMENT_DESCRIPTION__DOMAIN_TYPE });
// @formatter:on
diagnostics.add(basicDiagnostic);
}
return isValid;
}
use of org.eclipse.sirius.components.domain.Entity in project sirius-components by eclipse-sirius.
the class DomainConverterTests method testConvertEntityWithValidName.
@ParameterizedTest
@ValueSource(strings = { "lowercase", "snake_case", "CamelCase", "Sample_Entity", "A1" })
public void testConvertEntityWithValidName(String name) {
Domain fixture = DomainFactory.eINSTANCE.createDomain();
fixture.setName(FIXTURE);
Entity entity = DomainFactory.eINSTANCE.createEntity();
entity.setName(name);
fixture.getTypes().add(entity);
Optional<EPackage> converted = this.convert(fixture);
assertThat(converted).isPresent();
EList<EClassifier> convertedTypes = converted.get().getEClassifiers();
assertThat(convertedTypes).hasSize(1);
assertThat(convertedTypes.get(0)).extracting(EClassifier::getName).isEqualTo(name);
}
use of org.eclipse.sirius.components.domain.Entity in project sirius-components by eclipse-sirius.
the class DomainConverterTests method testConvertEntityWithInvalidName.
@ParameterizedTest
@ValueSource(strings = { "", "42", "almost!valid", "foo-bar", "foo.bar", "foo/bar" })
public void testConvertEntityWithInvalidName(String name) {
Domain fixture = DomainFactory.eINSTANCE.createDomain();
fixture.setName(FIXTURE);
Entity invalidEntity = DomainFactory.eINSTANCE.createEntity();
invalidEntity.setName(name);
fixture.getTypes().add(invalidEntity);
Optional<EPackage> converted = this.convert(fixture);
assertThat(converted).isEmpty();
}
use of org.eclipse.sirius.components.domain.Entity in project sirius-components by eclipse-sirius.
the class DomainConverterTests method testConvertEntityWithNullName.
@Test
public void testConvertEntityWithNullName() {
Domain fixture = DomainFactory.eINSTANCE.createDomain();
fixture.setName(FIXTURE);
Entity invalidEntity = DomainFactory.eINSTANCE.createEntity();
invalidEntity.setName(null);
fixture.getTypes().add(invalidEntity);
Optional<EPackage> converted = this.convert(fixture);
assertThat(converted).isEmpty();
}
use of org.eclipse.sirius.components.domain.Entity in project sirius-components by eclipse-sirius.
the class DomainConverterTests method testConvertSystemDomainDefinition.
@Test
void testConvertSystemDomainDefinition() {
Domain componentDomain = DomainFactory.eINSTANCE.createDomain();
// $NON-NLS-1$
componentDomain.setName("component");
Entity namedEntity = DomainFactory.eINSTANCE.createEntity();
// $NON-NLS-1$
namedEntity.setName("Named");
namedEntity.setAbstract(true);
Attribute nameAttribute = DomainFactory.eINSTANCE.createAttribute();
// $NON-NLS-1$
nameAttribute.setName("name");
nameAttribute.setMany(false);
nameAttribute.setOptional(false);
nameAttribute.setType(DataType.STRING);
namedEntity.getAttributes().add(nameAttribute);
componentDomain.getTypes().add(namedEntity);
Entity systemEntity = DomainFactory.eINSTANCE.createEntity();
// $NON-NLS-1$
systemEntity.setName("System");
systemEntity.getSuperTypes().add(namedEntity);
componentDomain.getTypes().add(systemEntity);
Entity componentEntity = DomainFactory.eINSTANCE.createEntity();
// $NON-NLS-1$
componentEntity.setName("Component");
componentEntity.getSuperTypes().add(namedEntity);
componentDomain.getTypes().add(componentEntity);
Relation systemComponentsRelation = DomainFactory.eINSTANCE.createRelation();
// $NON-NLS-1$
systemComponentsRelation.setName("parts");
systemComponentsRelation.setContainment(true);
systemComponentsRelation.setMany(true);
systemComponentsRelation.setOptional(true);
systemComponentsRelation.setTargetType(componentEntity);
systemEntity.getRelations().add(systemComponentsRelation);
Optional<EPackage> converted = this.convert(componentDomain);
assertThat(converted).isPresent();
EPackage convertedPackage = converted.get();
assertThat(convertedPackage.getEClassifiers()).hasSize(3);
// @formatter:off
assertThat(convertedPackage.getEClassifier(namedEntity.getName())).asInstanceOf(InstanceOfAssertFactories.type(EClass.class)).matches(EClass::isAbstract).matches(eClass -> eClass.getEAllAttributes().size() == 1).matches(eClass -> eClass.getEAllReferences().isEmpty());
assertThat(convertedPackage.getEClassifier(systemEntity.getName())).asInstanceOf(InstanceOfAssertFactories.type(EClass.class)).matches(eClass -> !eClass.isAbstract()).matches(eClass -> eClass.getESuperTypes().size() == 1).matches(eClass -> eClass.getEAttributes().isEmpty()).matches(eClass -> eClass.getEAllAttributes().size() == 1);
assertThat(convertedPackage.getEClassifier(componentEntity.getName())).asInstanceOf(InstanceOfAssertFactories.type(EClass.class)).matches(eClass -> !eClass.isAbstract()).matches(eClass -> eClass.getESuperTypes().size() == 1).matches(eClass -> eClass.getEAttributes().isEmpty()).matches(eClass -> eClass.getEAllAttributes().size() == 1);
// @formatter:on
}
Aggregations