use of org.eclipse.sirius.web.services.api.projects.RepresentationManifest in project sirius-web by eclipse-sirius.
the class ProjectExportService method addRepresentation.
/**
* Adds a {@link ZipEntry} for every representations in the project, in the given {@link ZipOutputStream}.
*
* <p>
* The name of the {@link ZipEntry} is [projectName]/representations/[representationId], where '/' are used as path
* separator in the zip.
* </p>
*
* <p>
* Returns a map of representation IDs to {@link RepresentationManifest}. This map will be stored in the manifest
* file.
* </p>
*
* @param projectId
* The id of the project we want to export
* @param projectName
* The name of the project we want to export
* @param zippedOut
* The {@link ZipOutputStream} used to build the zip
* @return the mapping between representation IDs and their {@link RepresentationManifest}
* @throws IOException
* if an I/O error occurred
*/
private Map<String, RepresentationManifest> addRepresentation(String projectId, String projectName, ZipOutputStream zippedout) throws IOException {
List<RepresentationDescriptor> representationsDescriptor = this.representationService.getRepresentationDescriptorsForProjectId(projectId);
Map<String, RepresentationManifest> representationManifests = new HashMap<>();
ResourceSet resourceSet = this.loadAllDocuments(projectId);
for (RepresentationDescriptor representationDescriptor : representationsDescriptor) {
RepresentationManifest representationManifest = this.createRepresentationManifest(representationDescriptor, resourceSet);
UUID representationId = representationDescriptor.getId();
representationManifests.put(representationId.toString(), representationManifest);
byte[] bytes = new ObjectMapper().writeValueAsBytes(representationDescriptor);
// $NON-NLS-1$ //$NON-NLS-2$
String name = projectName + "/representations/" + representationId + "." + JsonResourceFactoryImpl.EXTENSION;
ZipEntry zipEntry = this.createZipEntry(name, bytes.length);
zippedout.putNextEntry(zipEntry);
zippedout.write(bytes);
zippedout.closeEntry();
}
return representationManifests;
}
use of org.eclipse.sirius.web.services.api.projects.RepresentationManifest in project sirius-web by eclipse-sirius.
the class ProjectExportService method toZip.
private byte[] toZip(Project project) {
byte[] zip = new byte[0];
String projectId = project.getId().toString();
String projectName = project.getName();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try (var zippedOut = new ZipOutputStream(outputStream)) {
Map<String, String> id2DocumentName = this.addDocuments(projectId, projectName, zippedOut);
Map<String, RepresentationManifest> representationsManifests = this.addRepresentation(projectId, projectName, zippedOut);
this.addManifest(projectId, projectName, id2DocumentName, representationsManifests, zippedOut);
} catch (IOException exception) {
this.logger.warn(exception.getMessage(), exception);
outputStream.reset();
}
if (outputStream.size() > 0) {
zip = outputStream.toByteArray();
}
return zip;
}
use of org.eclipse.sirius.web.services.api.projects.RepresentationManifest 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;
}
Aggregations