use of org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessor in project sirius-components by eclipse-sirius.
the class EditingContextEventProcessorRegistry method getOrCreateEditingContextEventProcessor.
@Override
public synchronized Optional<IEditingContextEventProcessor> getOrCreateEditingContextEventProcessor(String editingContextId) {
Optional<IEditingContextEventProcessor> optionalEditingContextEventProcessor = Optional.empty();
if (this.editingContextSearchService.existsById(editingContextId)) {
optionalEditingContextEventProcessor = Optional.ofNullable(this.editingContextEventProcessors.get(editingContextId)).map(EditingContextEventProcessorEntry::getEditingContextEventProcessor);
if (optionalEditingContextEventProcessor.isEmpty()) {
Optional<IEditingContext> optionalEditingContext = this.editingContextSearchService.findById(editingContextId);
if (optionalEditingContext.isPresent()) {
IEditingContext editingContext = optionalEditingContext.get();
var editingContextEventProcessor = this.editingContextEventProcessorFactory.createEditingContextEventProcessor(editingContext);
Disposable subscription = editingContextEventProcessor.canBeDisposed().delayElements(this.disposeDelay).subscribe(canBeDisposed -> {
// We will check if the editing context event processor is still empty
if (canBeDisposed.booleanValue() && editingContextEventProcessor.getRepresentationEventProcessors().isEmpty()) {
this.disposeEditingContextEventProcessor(editingContextId);
} else {
// $NON-NLS-1$
this.logger.trace("Stopping the disposal of the editing context");
}
});
var editingContextEventProcessorEntry = new EditingContextEventProcessorEntry(editingContextEventProcessor, subscription);
this.editingContextEventProcessors.put(editingContextId, editingContextEventProcessorEntry);
optionalEditingContextEventProcessor = Optional.of(editingContextEventProcessor);
}
}
}
return optionalEditingContextEventProcessor;
}
use of org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessor in project sirius-web by eclipse-sirius.
the class ProjectImportService method importProject.
/**
* Returns {@link UploadProjectSuccessPayload} if the project import has been successful, {@link ErrorPayload}
* otherwise.
*
* <p>
* Unzip the given {@link UploadFile}, then creates a project with the name of the root directory in the zip file,
* then use {@link ProjectImporter} to create documents and representations. If the project has not been imported,
* it disposes the {@link IEditingContextEventProcessor} used to create documents and representations then delete
* the created project in order to keep the server in the same state before the project upload attempt.
* </p>
*
* @param inputId
* The identifier of the input which has triggered the upload
* @param file
* the file to upload
* @return {@link UploadProjectSuccessPayload} whether the project import has been successful, {@link ErrorPayload}
* otherwise
*/
@Override
public IPayload importProject(UUID inputId, UploadFile file) {
IPayload payload = new ErrorPayload(inputId, this.messageService.unexpectedError());
ProjectUnzipper unzipper = new ProjectUnzipper(file.getInputStream(), this.objectMapper);
Optional<UnzippedProject> optionalUnzippedProject = unzipper.unzipProject();
if (optionalUnzippedProject.isEmpty()) {
return new ErrorPayload(inputId, this.messageService.unexpectedError());
}
UnzippedProject unzippedProject = optionalUnzippedProject.get();
ProjectManifest manifest = unzippedProject.getProjectManifest();
String projectName = unzippedProject.getProjectName();
CreateProjectInput createProjectInput = new CreateProjectInput(inputId, projectName, Visibility.PRIVATE);
IPayload createProjectPayload = this.projectService.createProject(createProjectInput);
if (createProjectPayload instanceof CreateProjectSuccessPayload) {
Project project = ((CreateProjectSuccessPayload) createProjectPayload).getProject();
Optional<IEditingContextEventProcessor> optionalEditingContextEventProcessor = this.editingContextEventProcessorRegistry.getOrCreateEditingContextEventProcessor(project.getId().toString());
if (optionalEditingContextEventProcessor.isPresent()) {
IEditingContextEventProcessor editingContextEventProcessor = optionalEditingContextEventProcessor.get();
Map<String, UploadFile> documents = unzippedProject.getDocumentIdToUploadFile();
List<RepresentationDescriptor> representations = unzippedProject.getRepresentationDescriptors();
ProjectImporter projectImporter = new ProjectImporter(project.getId().toString(), editingContextEventProcessor, documents, representations, manifest, this.idMappingRepository);
boolean hasBeenImported = projectImporter.importProject(inputId);
if (!hasBeenImported) {
this.editingContextEventProcessorRegistry.disposeEditingContextEventProcessor(project.getId().toString());
this.projectService.delete(project.getId());
} else {
payload = new UploadProjectSuccessPayload(inputId, project);
}
}
}
return payload;
}
Aggregations