use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.
the class ModelRepository method doGetLinksInSession.
private Set<ModelLink> doGetLinksInSession(ModelId modelID, Session session) throws RepositoryException {
ObjectMapper objectMapper = ObjectMapperFactory.getInstance();
Node fileNode = getFileNode(modelID, session);
if (fileNode.hasProperty(VORTO_LINKS)) {
return getVortoLinksPropertyValues(fileNode.getProperty(VORTO_LINKS)).stream().map(value -> deserializeLinkDto(objectMapper, value)).collect(Collectors.toSet());
}
return Collections.emptySet();
}
use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.
the class NamespaceRequestCache method namespace.
/**
* Resolves a cached {@link Namespace} by name if applicable.<br/>
* This will also attempt to resolve a "virtual" namespace string, consisting in the real
* namespace appended with an arbitrary number of {@literal .[sub-namespace]} strings to the
* root namespace.<br/>
* The latter is useful when invoking e.g. {@link NamespaceService#getByName(String)} with
* {@link ModelId#getNamespace()} since the latter does not trim out the "virtual" sub-namespaces.
* <br/>
* For instance, when given {@literal com.bosch.iot.suite.example.octopussuiteedition}:
* <ol>
* <li>
* Attempts to resolve {@literal com.bosch.iot.suite.example.octopussuiteedition} and get
* its workspace ID, which fails
* </li>
* <li>
* Attempts to resolve {@literal com.bosch.iot.suite.example} and get its workspace ID, which
* fails again
* </li>
* <li>
* Attempts to resolve {@literal com.bosch.iot.suite} and get its workspace ID, which
* succeeds
* </li>
* </ol>
* Note: virtual namespaces are cached within the scope of a request. <br/>
*
* @param name
* @return
*/
public Optional<Namespace> namespace(String name) {
// boilerplate null/empty checks
if (Objects.isNull(name) || name.trim().isEmpty()) {
return Optional.empty();
}
// lazy population
populateIfEmpty();
// lookup into virtual namespace map first
if (virtualNamespaces.containsKey(name)) {
Namespace result = virtualNamespaces.get(name);
LOGGER.debug(String.format("Resolved virtual namespace [%s] to [%s]", name, result.getName()));
return Optional.of(result);
}
// resolving by name equality
Optional<Namespace> result = this.namespaces.stream().filter(n -> n.getName().equals(name)).findAny();
if (result.isPresent()) {
LOGGER.debug(String.format("Resolved namespace [%s]", name));
return result;
} else {
return resolveVirtualNamespaceRecursively(name, name);
}
}
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()));
}
}
Aggregations