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;
}
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();
}
}
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();
}
}
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);
}
Aggregations