use of org.eclipse.vorto.model.EntityModel in project vorto by eclipse.
the class ModelContentToEcoreConverterTest method testConvertDatatype.
@Test
public void testConvertDatatype() {
EntityModel entityModel = EntityModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Location:1.0.0")).property(ModelProperty.Builder("lng", PrimitiveType.FLOAT).withConstraint(ConstraintType.MIN, "0").build()).property(ModelProperty.Builder("lat", PrimitiveType.STRING).build()).description("Some description").displayname("Location").build();
ModelContentToEcoreConverter converter = new ModelContentToEcoreConverter();
Entity model = (Entity) converter.convert(ModelContent.Builder(entityModel).build(), Optional.empty());
assertEquals(entityModel.getId().getNamespace(), model.getNamespace());
assertEquals(entityModel.getId().getName(), model.getName());
assertEquals(entityModel.getId().getVersion(), model.getVersion());
assertEquals(entityModel.getDescription(), model.getDescription());
assertEquals(entityModel.getDisplayName(), model.getDisplayname());
assertEquals(entityModel.getCategory(), model.getCategory());
assertEquals(2, model.getProperties().size());
Property property1 = model.getProperties().stream().filter(p -> p.getName().equals("lng")).findAny().get();
assertNotNull(property1);
assertEquals(org.eclipse.vorto.core.api.model.datatype.PrimitiveType.FLOAT, ((PrimitivePropertyType) property1.getType()).getType());
assertEquals(1, property1.getConstraintRule().getConstraints().size());
Property property2 = model.getProperties().stream().filter(p -> p.getName().equals("lat")).findAny().get();
assertNotNull(property2);
assertEquals(org.eclipse.vorto.core.api.model.datatype.PrimitiveType.STRING, ((PrimitivePropertyType) property2.getType()).getType());
}
use of org.eclipse.vorto.model.EntityModel in project vorto by eclipse.
the class DefaultPayloadMappingService method addReferencesRecursive.
/**
* Adds reference types of the given properties to the mapping Specification (needed for lookup)
*
* @param model to traverse properties
*/
private void addReferencesRecursive(IModel model, String targetPlatformKey) {
if (model instanceof Infomodel) {
Infomodel infomodel = (Infomodel) model;
for (ModelProperty property : infomodel.getFunctionblocks()) {
ModelId referenceModelId = (ModelId) property.getType();
ModelId mappingId = property.getMappingReference();
IModel referenceModel = null;
if (mappingId != null) {
referenceModel = getModelContentByModelAndMappingId(referenceModelId.getPrettyFormat(), mappingId.getPrettyFormat());
} else {
ModelContent modelContent = getModelContent(referenceModelId, targetPlatformKey);
referenceModel = modelContent.getModels().get(modelContent.getRoot());
}
property.setType((FunctionblockModel) referenceModel);
addReferencesRecursive(referenceModel, targetPlatformKey);
}
} else if (model instanceof EntityModel) {
EntityModel entityModel = (EntityModel) model;
for (ModelProperty property : entityModel.getProperties()) {
initStereotypeIfMissing(property);
if (property.getType() instanceof ModelId) {
ModelId referenceModelId = (ModelId) property.getType();
ModelId mappingId = property.getMappingReference();
IModel referenceModel = null;
if (mappingId != null) {
referenceModel = getModelContentByModelAndMappingId(referenceModelId.getPrettyFormat(), mappingId.getPrettyFormat());
} else {
ModelContent modelContent = getModelContent(referenceModelId, targetPlatformKey);
referenceModel = modelContent.getModels().get(modelContent.getRoot());
}
if (referenceModel instanceof EntityModel) {
property.setType((EntityModel) referenceModel);
addReferencesRecursive(referenceModel, targetPlatformKey);
} else {
property.setType((EnumModel) referenceModel);
}
}
}
} else if (model instanceof FunctionblockModel) {
FunctionblockModel fbModel = (FunctionblockModel) model;
for (ModelProperty property : fbModel.getProperties()) {
initStereotypeIfMissing(property);
if (property.getType() instanceof ModelId) {
ModelId referenceModelId = (ModelId) property.getType();
ModelId mappingId = property.getMappingReference();
IModel referenceModel = null;
if (mappingId != null) {
referenceModel = getModelContentByModelAndMappingId(referenceModelId.getPrettyFormat(), mappingId.getPrettyFormat());
} else {
ModelContent modelContent = getModelContent(referenceModelId, targetPlatformKey);
referenceModel = modelContent.getModels().get(modelContent.getRoot());
}
if (referenceModel instanceof EntityModel) {
property.setType((EntityModel) referenceModel);
addReferencesRecursive(referenceModel, targetPlatformKey);
} else {
property.setType((EnumModel) referenceModel);
}
}
}
}
}
use of org.eclipse.vorto.model.EntityModel in project vorto by eclipse.
the class ModelIdToModelContentConverterTest method testConvertWithoutTargetPlatformLatestTag.
@Test
public void testConvertWithoutTargetPlatformLatestTag() throws Exception {
setupTestDataForLatestTag();
ModelIdToModelContentConverter converter = new ModelIdToModelContentConverter(this.repositoryFactory);
ModelContent content = converter.convert(ModelId.fromPrettyFormat("org.eclipse.vorto.examples.type:Color:latest"), Optional.empty());
assertEquals(ModelId.fromPrettyFormat("org.eclipse.vorto.examples.type:Color:1.0.1"), content.getModels().get(content.getRoot()).getId());
assertEquals(0, ((EntityModel) content.getModels().get(content.getRoot())).getStereotypes().size());
}
use of org.eclipse.vorto.model.EntityModel in project vorto by eclipse.
the class ModelIdToModelContentConverterTest method testConvertWithoutTargetPlatform.
@Test
public void testConvertWithoutTargetPlatform() throws Exception {
importModel("Color.type");
importModel("sample.mapping");
ModelIdToModelContentConverter converter = new ModelIdToModelContentConverter(this.repositoryFactory);
ModelContent content = converter.convert(ModelId.fromPrettyFormat("org.eclipse.vorto.examples.type:Color:1.0.0"), Optional.empty());
assertEquals(ModelId.fromPrettyFormat("org.eclipse.vorto.examples.type:Color:1.0.0"), content.getModels().get(content.getRoot()).getId());
assertEquals(0, ((EntityModel) content.getModels().get(content.getRoot())).getStereotypes().size());
}
use of org.eclipse.vorto.model.EntityModel in project vorto by eclipse.
the class MappingSpecificationSerializer method addSerializerRecursive.
private void addSerializerRecursive(ModelId parentId, IModel container, List<ModelProperty> properties, List<IMappingSerializer> serializers) {
for (ModelProperty property : properties) {
if (isEntityProperty(property)) {
EntityModel entityModel = (EntityModel) property.getType();
ModelId mappingId = MappingIdUtils.getIdForProperty(parentId, property);
addSerializerRecursive(mappingId, entityModel, entityModel.getProperties(), serializers);
serializers.add(new EntityMappingSerializer(specification, mappingId, targetPlatform, property.getName(), entityModel));
}
}
}
Aggregations