private void createSimpleEnvironment() {
    currentProject = appContext.getCurrentProject();
    if (currentProject == null) {
      return;
    }

    final String fileName =
        NameGenerator.generateCustomEnvironmentName(
            templatesPresenter.getProjectEnvironments(),
            currentProject.getProjectDescription().getName());
    String path = currentProject.getProjectDescription().getPath() + ROOT_FOLDER + fileName;

    AsyncRequestCallback<ItemReference> callback =
        asyncCallbackBuilder
            .unmarshaller(ItemReference.class)
            .success(
                new SuccessCallback<ItemReference>() {
                  @Override
                  public void onSuccess(ItemReference result) {
                    createFile(resources.dockerTemplate().getText(), fileName);
                  }
                })
            .failure(
                new FailureCallback() {
                  @Override
                  public void onFailure(@Nonnull Throwable reason) {
                    notificationManager.showError(reason.getMessage());
                  }
                })
            .build();

    projectService.createFolder(path, callback);
  }
  private void estimateAndSetAttributes() {
    projectServiceClient.estimateProject(
        context.get(PROJECT_PATH_KEY),
        MAVEN_ID,
        new AsyncRequestCallback<Map<String, List<String>>>(new StringMapListUnmarshaller()) {
          @Override
          protected void onSuccess(Map<String, List<String>> result) {
            List<String> artifactIdValues = result.get(ARTIFACT_ID);
            if (artifactIdValues != null && !artifactIdValues.isEmpty()) {
              setAttribute(ARTIFACT_ID, artifactIdValues.get(0));
            }

            List<String> groupIdValues = result.get(GROUP_ID);
            List<String> parentGroupIdValues = result.get(PARENT_GROUP_ID);
            if (groupIdValues != null && !groupIdValues.isEmpty()) {
              setAttribute(GROUP_ID, groupIdValues.get(0));
            } else if (parentGroupIdValues != null && !parentGroupIdValues.isEmpty()) {
              setAttribute(GROUP_ID, parentGroupIdValues.get(0));
            }

            List<String> versionValues = result.get(VERSION);
            List<String> parentVersionValues = result.get(PARENT_VERSION);
            if (versionValues != null && !versionValues.isEmpty()) {
              setAttribute(VERSION, versionValues.get(0));
            } else if (parentVersionValues != null && !parentVersionValues.isEmpty()) {
              setAttribute(VERSION, parentVersionValues.get(0));
            }

            List<String> packagingValues = result.get(PACKAGING);
            if (packagingValues != null && !packagingValues.isEmpty()) {
              setAttribute(PACKAGING, packagingValues.get(0));
            }

            updateDelegate.updateControls();
          }

          @Override
          protected void onFailure(Throwable exception) {
            final String message =
                dtoFactory
                    .createDtoFromJson(exception.getMessage(), ServiceError.class)
                    .getMessage();
            dialogFactory.createMessageDialog("Not valid Maven project", message, null).show();
            Log.error(MavenPagePresenter.class, exception);
          }
        });
  }
  /** {@inheritDoc} */
  @Override
  public void onOpen() {
    if (Config.getProjectName() == null) {
      setTree(projectListStructureProvider.get());
    } else {
      projectServiceClient.getProject(
          Config.getProjectName(),
          new AsyncRequestCallback<ProjectDescriptor>() {
            @Override
            protected void onSuccess(ProjectDescriptor result) {}

            @Override
            protected void onFailure(Throwable exception) {
              setTree(projectListStructureProvider.get());
            }
          });
    }
  }
Beispiel #4
0
 private void updateProject(final ProjectConfigDto projectToUpdate) {
   Promise<ProjectConfigDto> updateProjectPromise =
       projectService.updateProject(workspaceId, projectToUpdate.getPath(), projectToUpdate);
   updateProjectPromise
       .then(
           new Operation<ProjectConfigDto>() {
             @Override
             public void apply(ProjectConfigDto arg) throws OperationException {
               updateOpenedFiles();
               eventBus.fireEvent(new ProjectUpdatedEvent(arg.getPath(), arg));
             }
           })
       .catchError(
           new Operation<PromiseError>() {
             @Override
             public void apply(PromiseError arg) throws OperationException {
               notificationManager.notify(arg.getMessage(), FAIL, true, projectToUpdate);
             }
           });
 }
  private void setupMixin(Project project) {
    final ProjectConfigDto projectConfig = appContext.getCurrentProject().getRootProject();

    List<String> mixins = projectConfig.getMixins();
    if (!mixins.contains(OPENSHIFT_PROJECT_TYPE_ID)) {
      mixins.add(OPENSHIFT_PROJECT_TYPE_ID);
    }

    Map<String, List<String>> attributes = projectConfig.getAttributes();
    attributes.put(OPENSHIFT_APPLICATION_VARIABLE_NAME, newArrayList(osAppName));
    attributes.put(
        OPENSHIFT_NAMESPACE_VARIABLE_NAME, newArrayList(project.getMetadata().getName()));

    projectService
        .updateProject(appContext.getWorkspaceId(), projectConfig.getPath(), projectConfig)
        .then(
            new Operation<ProjectConfigDto>() {
              @Override
              public void apply(ProjectConfigDto project) throws OperationException {
                eventBus.fireEvent(new ProjectUpdatedEvent(projectConfig.getPath(), project));
                notificationManager.notify(
                    locale.linkProjectWithExistingSuccess(projectConfig.getName(), osAppName),
                    SUCCESS,
                    true);
              }
            })
        .catchError(
            new Operation<PromiseError>() {
              @Override
              public void apply(PromiseError arg) throws OperationException {
                final ServiceError serviceError =
                    dtoFactory.createDtoFromJson(arg.getMessage(), ServiceError.class);
                notificationManager.notify(serviceError.getMessage(), FAIL, true);
              }
            });
  }
  private void createFile(@Nonnull String content, @Nonnull String fileName) {
    String path = currentProject.getProjectDescription().getPath() + ROOT_FOLDER;

    AsyncRequestCallback<ItemReference> callback =
        asyncCallbackBuilder
            .unmarshaller(ItemReference.class)
            .success(
                new SuccessCallback<ItemReference>() {
                  @Override
                  public void onSuccess(ItemReference result) {
                    getProjectEnvironmentsAction.perform();
                  }
                })
            .failure(
                new FailureCallback() {
                  @Override
                  public void onFailure(@Nonnull Throwable reason) {
                    Log.error(PropertiesPanelPresenter.class, reason.getMessage());
                  }
                })
            .build();

    projectService.createFile(path, fileName + DOCKER_SCRIPT_NAME, content, null, callback);
  }
Beispiel #7
0
  private void updateOpenedFiles() {
    for (EditorPartPresenter editorPartPresenter : editorAgent.getOpenedEditors().values()) {
      final VirtualFile file = editorPartPresenter.getEditorInput().getFile();
      final String filePath = file.getPath();
      Unmarshallable<ItemReference> unmarshaller =
          dtoUnmarshallerFactory.newUnmarshaller(ItemReference.class);

      projectService.getItem(
          workspaceId,
          filePath,
          new AsyncRequestCallback<org.eclipse.che.api.project.shared.dto.ItemReference>(
              unmarshaller) {
            @Override
            protected void onSuccess(ItemReference itemReference) {
              eventBus.fireEvent(new FileContentUpdateEvent(filePath));
            }

            @Override
            protected void onFailure(Throwable throwable) {
              eventBus.fireEvent(new FileEvent(file, FileEvent.FileOperation.CLOSE));
            }
          });
    }
  }