use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.
the class AbstractModelParser method parseModelIdFromFileName.
private ModelId parseModelIdFromFileName() {
String pureFileName = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.lastIndexOf("."));
ModelId modelId = new ModelId();
try {
modelId.setNamespace(pureFileName.substring(0, pureFileName.lastIndexOf(".")));
modelId.setName(pureFileName.substring(pureFileName.lastIndexOf(".") + 1, pureFileName.indexOf("_")));
String version = pureFileName.substring(pureFileName.indexOf("_") + 1);
version = version.replaceAll("_", ".");
modelId.setVersion(version.substring(0, 5));
} catch (Throwable t) {
return new ModelId(pureFileName, "", "0.0.0");
}
return modelId;
}
use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.
the class DefaultResolver method doResolve.
@Override
protected ModelId doResolve(String tenantId, ModelInfo mappingModelResource, ResolveQuery query) {
ModelFileContent content = getRepositoryFactory().getRepository(tenantId).getModelContent(mappingModelResource.getId(), false);
MappingModel mappingModel = (MappingModel) content.getModel();
Optional<MappingRule> objectRule = mappingModel.getRules().stream().filter(rule -> rule.getTarget() instanceof StereoTypeTarget && ((StereoTypeTarget) rule.getTarget()).getName().equals(query.getStereoType())).findFirst();
if (objectRule.isPresent()) {
Optional<Attribute> objectIdAttribute = ((StereoTypeTarget) objectRule.get().getTarget()).getAttributes().stream().filter(attribute -> attribute.getName().equals(query.getAttributeId())).findFirst();
if (objectIdAttribute.isPresent() && objectIdAttribute.get().getValue().equals(query.getAttributeValue())) {
return ModelId.fromReference(mappingModel.getReferences().get(0).getImportedNamespace(), mappingModel.getReferences().get(0).getVersion());
}
}
return null;
}
use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.
the class BulkUploadHelper method trytoCreateModelFromCorruptFile.
// TODO: try to guess the modelinfo based on the content of the file, instead of the filename
private ModelInfo trytoCreateModelFromCorruptFile(String fileName) {
try {
final String modelName = fileName.substring(0, fileName.lastIndexOf("."));
final ModelType type = ModelType.fromFileName(fileName);
return new ModelInfo(new ModelId(modelName, "unknown", "unknown"), type);
} catch (Throwable t) {
return null;
}
}
use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.
the class MetadataIntegrityDiagnostic method checkModelType.
private Optional<Diagnostic> checkModelType(final Node node) {
ModelId modelId = null;
try {
modelId = NodeDiagnosticUtils.getModelId(node.getPath()).orElseThrow(() -> new NodeDiagnosticException("Cannot get modelId of node"));
ModelType fileModelType = ModelType.create(node.getName());
ModelType nodeModelType = ModelType.valueOf(node.getProperty("vorto:type").getString());
if (!fileModelType.equals(nodeModelType)) {
String message = new StringBuilder("The model type should be '").append(fileModelType.name()).append("' but is '").append(nodeModelType.name()).append("'").toString();
return Optional.of(new Diagnostic(modelId, message));
}
return Optional.empty();
} catch (RepositoryException e) {
return Optional.of(new Diagnostic(modelId, "Got exception while checking node 'vorto:type' : " + e.getMessage()));
}
}
use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.
the class ModelRepositoryTest2 method testReferencedByApi.
@Test
public void testReferencedByApi() {
IUserContext creator = createUserContext("creator", "playground");
importModel("Color.type", creator);
importModel("Color4.type", creator);
importModel("Colorlight.fbmodel", creator);
importModel("Colorlight2.fbmodel", creator);
importModel("Colorlight3.fbmodel", creator);
List<ModelInfo> referencedBy = repositoryFactory.getRepository(creator).getModelsReferencing(new ModelId("Color", "org.eclipse.vorto.examples.type", "1.0.0"));
assertEquals(2, referencedBy.size());
assertTrue(referencedBy.stream().anyMatch(model -> model.getId().getName().equals("ColorLight")));
assertTrue(referencedBy.stream().anyMatch(model -> model.getId().getName().equals("ColorLight2")));
}
Aggregations