Search in sources :

Example 1 with IdMappingEntity

use of org.eclipse.sirius.web.persistence.entities.IdMappingEntity in project sirius-web by eclipse-sirius.

the class ProjectImporter method createRepresentations.

/**
 * Creates all representations in the project thanks to the {@link IEditingContextEventProcessor} and the create
 * representation input. If at least one representation has not been created it will return <code>false</code>.
 *
 * @param inputId
 *            The identifier of the input which has triggered this import
 *
 * @return <code>true</code> whether all representations has been created, <code>false</code> otherwise
 */
private boolean createRepresentations(UUID inputId) {
    boolean allRepresentationCreated = true;
    for (RepresentationDescriptor representationDescriptor : this.representations) {
        RepresentationManifest representationManifest = this.projectManifest.getRepresentations().get(representationDescriptor.getId().toString());
        String targetObjectURI = representationManifest.getTargetObjectURI();
        String oldDocumentId = URI.create(targetObjectURI).getPath();
        Document newDocument = this.oldDocumentIdToNewDocument.get(oldDocumentId);
        final String objectId;
        if (newDocument != null) {
            objectId = targetObjectURI.replace(oldDocumentId, newDocument.getId().toString());
        } else {
            objectId = targetObjectURI;
        }
        boolean representationCreated = false;
        String descriptionURI = representationManifest.getDescriptionURI();
        // @formatter:off
        var inputHandle = this.idMappingRepository.findByExternalId(descriptionURI).map(IdMappingEntity::getId).or(() -> Optional.of(descriptionURI)).map(representationDescriptionId -> new CreateRepresentationInput(inputId, this.projectId.toString(), representationDescriptionId.toString(), objectId, representationDescriptor.getLabel())).map(this.editingContextEventProcessor::handle).orElseGet(Mono::empty);
        representationCreated = inputHandle.filter(CreateRepresentationSuccessPayload.class::isInstance).map(CreateRepresentationSuccessPayload.class::cast).map(CreateRepresentationSuccessPayload::getRepresentation).blockOptional().isPresent();
        if (!representationCreated) {
            // $NON-NLS-1$
            this.logger.warn("The representation {} has not been created", representationDescriptor.getLabel());
        }
        allRepresentationCreated = allRepresentationCreated && representationCreated;
    }
    return allRepresentationCreated;
}
Also used : CreateRepresentationInput(org.eclipse.sirius.components.collaborative.dto.CreateRepresentationInput) IdMappingEntity(org.eclipse.sirius.web.persistence.entities.IdMappingEntity) RepresentationDescriptor(org.eclipse.sirius.web.services.api.representations.RepresentationDescriptor) Mono(reactor.core.publisher.Mono) CreateRepresentationSuccessPayload(org.eclipse.sirius.components.collaborative.dto.CreateRepresentationSuccessPayload) Document(org.eclipse.sirius.web.services.api.document.Document) RepresentationManifest(org.eclipse.sirius.web.services.api.projects.RepresentationManifest)

Example 2 with IdMappingEntity

use of org.eclipse.sirius.web.persistence.entities.IdMappingEntity in project sirius-web by eclipse-sirius.

the class IdentifierProvider method getOrFetchByExternalId.

private Optional<IdMappingEntity> getOrFetchByExternalId(String vsmElementId) {
    try {
        Callable<? extends IdMappingEntity> loader = () -> {
            return this.repository.findByExternalId(vsmElementId).orElseThrow(() -> this.loadingError(vsmElementId));
        };
        IdMappingEntity idMapping = this.idMappingByExternalId.get(vsmElementId, loader);
        return Optional.of(this.cached(idMapping));
    } catch (ExecutionException e) {
        // Do not log: it is expected not to find a mapping in the repo the first time.
        return Optional.empty();
    }
}
Also used : IdMappingEntity(org.eclipse.sirius.web.persistence.entities.IdMappingEntity) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with IdMappingEntity

use of org.eclipse.sirius.web.persistence.entities.IdMappingEntity in project sirius-web by eclipse-sirius.

the class IdentifierProvider method getOrFetchById.

private Optional<IdMappingEntity> getOrFetchById(String id) {
    try {
        Callable<? extends IdMappingEntity> loader = () -> {
            return this.repository.findById(id).orElseThrow(() -> this.loadingError(id.toString()));
        };
        IdMappingEntity idMapping = this.idMappingById.get(id, loader);
        return Optional.of(this.cached(idMapping));
    } catch (ExecutionException e) {
        // Do not log: it is expected not to find a mapping in the repo the first time.
        return Optional.empty();
    }
}
Also used : IdMappingEntity(org.eclipse.sirius.web.persistence.entities.IdMappingEntity) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with IdMappingEntity

use of org.eclipse.sirius.web.persistence.entities.IdMappingEntity in project sirius-web by eclipse-sirius.

the class IdentifierProvider method newIdMapping.

private IdMappingEntity newIdMapping(String vsmElementId) {
    IdMappingEntity idMappingEntity = new IdMappingEntity();
    idMappingEntity.setId(UUID.nameUUIDFromBytes(vsmElementId.getBytes()).toString());
    idMappingEntity.setExternalId(vsmElementId);
    idMappingEntity = this.repository.save(idMappingEntity);
    return this.cached(idMappingEntity);
}
Also used : IdMappingEntity(org.eclipse.sirius.web.persistence.entities.IdMappingEntity)

Aggregations

IdMappingEntity (org.eclipse.sirius.web.persistence.entities.IdMappingEntity)4 ExecutionException (java.util.concurrent.ExecutionException)2 CreateRepresentationInput (org.eclipse.sirius.components.collaborative.dto.CreateRepresentationInput)1 CreateRepresentationSuccessPayload (org.eclipse.sirius.components.collaborative.dto.CreateRepresentationSuccessPayload)1 Document (org.eclipse.sirius.web.services.api.document.Document)1 RepresentationManifest (org.eclipse.sirius.web.services.api.projects.RepresentationManifest)1 RepresentationDescriptor (org.eclipse.sirius.web.services.api.representations.RepresentationDescriptor)1 Mono (reactor.core.publisher.Mono)1