use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.
the class DefaultPayloadMappingService method saveSpecification.
@Override
public void saveSpecification(IMappingSpecification specification, IUserContext user) {
MappingSpecificationSerializer.create(specification).iterator().forEachRemaining(serializer -> {
final ModelId createdModelId = serializer.getModelId();
String serializedMapping = serializer.serialize();
LOGGER.trace(String.format("Saving mapping: %s", serializedMapping));
this.modelRepositoryFactory.getRepositoryByModel(createdModelId).save(createdModelId, serializedMapping.getBytes(), createdModelId.getName() + ".mapping", user, false);
try {
workflowService.start(createdModelId, user);
} catch (WorkflowException e) {
throw new RuntimeException("Could not start workflow for mapping model", e);
}
});
}
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 NodeDiagnosticUtils method getModelId.
public static Optional<ModelId> getModelId(String path) {
Collection<String> fragments = Arrays.asList(path.split("/")).stream().filter(str -> !Strings.isNullOrEmpty(str)).collect(Collectors.toList());
String[] pathFragments = fragments.toArray(new String[fragments.size()]);
if (ModelType.supports(pathFragments[pathFragments.length - 1])) {
if (pathFragments.length > 3) {
return Optional.of(new ModelId(pathFragments[pathFragments.length - 3], String.join(".", Arrays.copyOfRange(pathFragments, 0, pathFragments.length - 3)), pathFragments[pathFragments.length - 2]));
}
} else {
if (pathFragments.length > 2) {
return Optional.of(new ModelId(pathFragments[pathFragments.length - 2], String.join(".", Arrays.copyOfRange(pathFragments, 0, pathFragments.length - 2)), pathFragments[pathFragments.length - 1]));
}
}
return Optional.empty();
}
use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.
the class ModelRepository method doAttachFileInSession.
private boolean doAttachFileInSession(ModelId modelId, FileContent fileContent, IUserContext userContext, Session session, Tag[] tags) throws RepositoryException {
try {
ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
Node modelFolderNode = session.getNode(modelIdHelper.getFullPath());
Node attachmentFolderNode;
if (!modelFolderNode.hasNode(ATTACHMENTS_NODE)) {
attachmentFolderNode = modelFolderNode.addNode(ATTACHMENTS_NODE, NT_FOLDER);
} else {
attachmentFolderNode = modelFolderNode.getNode(ATTACHMENTS_NODE);
}
String[] tagIds = Arrays.stream(tags).filter(Objects::nonNull).map(Tag::getId).collect(Collectors.toList()).toArray(new String[tags.length]);
// purposes), removes the tag from all other attachments
if (Arrays.asList(tags).contains(TAG_DISPLAY_IMAGE)) {
NodeIterator attachments = attachmentFolderNode.getNodes();
while (attachments.hasNext()) {
Node next = attachments.nextNode();
Property attachmentTags = next.getProperty(VORTO_TAGS);
Value[] attachmentTagsValuesFiltered = Arrays.stream(attachmentTags.getValues()).filter(v -> {
try {
return !v.getString().equals(TAG_DISPLAY_IMAGE.getId());
// swallowing here
} catch (RepositoryException re) {
return false;
}
}).toArray(Value[]::new);
next.setProperty(VORTO_TAGS, attachmentTagsValuesFiltered);
}
}
Node contentNode;
if (attachmentFolderNode.hasNode(fileContent.getFileName())) {
Node attachmentNode = attachmentFolderNode.getNode(fileContent.getFileName());
attachmentNode.addMixin(VORTO_META);
attachmentNode.setProperty(VORTO_TAGS, tagIds, PropertyType.STRING);
contentNode = (Node) attachmentNode.getPrimaryItem();
} else {
Node attachmentNode = attachmentFolderNode.addNode(fileContent.getFileName(), NT_FILE);
attachmentNode.addMixin(VORTO_META);
attachmentNode.setProperty(VORTO_TAGS, tagIds, PropertyType.STRING);
contentNode = attachmentNode.addNode(JCR_CONTENT, NT_RESOURCE);
}
Binary binary = session.getValueFactory().createBinary(new ByteArrayInputStream(fileContent.getContent()));
contentNode.setProperty(JCR_DATA, binary);
session.save();
eventPublisher.publishEvent(new AppEvent(this, getById(modelId), userContext, EventType.MODEL_UPDATED));
return true;
} catch (AccessDeniedException e) {
throw new NotAuthorizedException(modelId, e);
}
}
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();
}
Aggregations