-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3279] Add import functionality and fix export
Bug: #3279 Signed-off-by: Jessy Mallet <[email protected]>
- Loading branch information
1 parent
645c4e3
commit 5c6d136
Showing
23 changed files
with
1,352 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
.../eclipse/sirius/web/application/project/controllers/MutationUploadProjectDataFetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
|
||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...java/org/eclipse/sirius/web/application/project/services/CreateProjectSuccessPayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.