Skip to content

Commit

Permalink
[3279] Add import functionality and fix export
Browse files Browse the repository at this point in the history
Bug: #3279
Signed-off-by: Jessy Mallet <[email protected]>
  • Loading branch information
jessymallet authored and sbegaudeau committed Jul 1, 2024
1 parent 645c4e3 commit 5c6d136
Show file tree
Hide file tree
Showing 23 changed files with 1,352 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
*
* @author sbegaudeau
*/
public record UploadDocumentSuccessPayload(@NotNull UUID id, String report) implements IPayload {
public record UploadDocumentSuccessPayload(@NotNull UUID id, String report, UUID newDocumentId) implements IPayload {
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.components.emf.services.JSONResourceFactory;
import org.eclipse.sirius.components.emf.services.api.IEMFEditingContext;
import org.eclipse.sirius.web.application.UUIDParser;
import org.eclipse.sirius.web.application.document.dto.UploadDocumentInput;
import org.eclipse.sirius.web.application.document.dto.UploadDocumentSuccessPayload;
import org.eclipse.sirius.web.application.document.services.api.IDocumentSanitizedJsonContentProvider;
Expand Down Expand Up @@ -118,8 +119,13 @@ public void handle(Sinks.One<IPayload> payloadSink, Sinks.Many<ChangeDescription
if (newResource.isPresent()) {
report = this.getReport(newResource.get());
}
payload = new UploadDocumentSuccessPayload(input.id(), report);
changeDescription = new ChangeDescription(ChangeKind.SEMANTIC_CHANGE, editingContext.getId(), input);
var newResourceId = newResource.get().getURI().path().substring(1);
Optional<UUID> optionalDocumentId = new UUIDParser().parse(newResourceId);
if (optionalDocumentId.isPresent()) {
var documentId = optionalDocumentId.get();
payload = new UploadDocumentSuccessPayload(input.id(), report, documentId);
changeDescription = new ChangeDescription(ChangeKind.SEMANTIC_CHANGE, editingContext.getId(), input);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.application.project.controllers;

import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;

import org.eclipse.sirius.components.annotations.spring.graphql.MutationDataFetcher;
import org.eclipse.sirius.components.core.api.ErrorPayload;
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates;
import org.eclipse.sirius.components.graphql.api.UploadFile;
import org.eclipse.sirius.web.application.UUIDParser;
import org.eclipse.sirius.web.application.project.services.api.IProjectImportService;
import org.eclipse.sirius.web.domain.services.api.IMessageService;

import graphql.schema.DataFetchingEnvironment;

/**
* The data fetcher used to create a new {@link Project} thanks to an {@link UploadProjectInput}.
* <p>
* It will be used to handle the following GraphQL field:
* </p>
*
* <pre>
* type Mutation {
* uploadProject(input: UploadProjectInput!): UploadProjectPayload!
* }
* </pre>
*
* @author gcoutable
*/
@MutationDataFetcher(type = "Mutation", field = "uploadProject")
public class MutationUploadProjectDataFetcher implements IDataFetcherWithFieldCoordinates<IPayload> {

private static final String INPUT_ARGUMENT = "input";

private static final String ID = "id";

private static final String FILE = "file";

private final IProjectImportService projectImportService;

private final IMessageService messageService;

public MutationUploadProjectDataFetcher(IProjectImportService projectImportService, IMessageService messageService) {
this.projectImportService = Objects.requireNonNull(projectImportService);
this.messageService = Objects.requireNonNull(messageService);
}

@Override
public IPayload get(DataFetchingEnvironment environment) throws Exception {
Map<Object, Object> input = environment.getArgument(INPUT_ARGUMENT);

var optionalId = Optional.ofNullable(input.get(ID)).map(Object::toString).flatMap(new UUIDParser()::parse);

var optionalFile = Optional.ofNullable(input.get(FILE)).filter(UploadFile.class::isInstance).map(UploadFile.class::cast);

if (optionalId.isPresent() && optionalFile.isPresent()) {
var id = optionalId.get();
var uploadFile = optionalFile.get();
return this.projectImportService.importProject(id, uploadFile);
}

return new ErrorPayload(optionalId.orElse(UUID.randomUUID()), this.messageService.unexpectedError());

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.application.project.services;

import java.util.Objects;
import java.util.UUID;

import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.web.domain.boundedcontexts.project.Project;

/**
* The payload of the create project mutation.
*
* @author jmallet
*/
public record CreateProjectSuccessPayload(UUID id, Project project) implements IPayload {
public CreateProjectSuccessPayload {
Objects.requireNonNull(id);
Objects.requireNonNull(project);
}
}
Loading

0 comments on commit 5c6d136

Please sign in to comment.