private void handleError(PromiseError error) {
   view.showLoader(false);
   final ServiceError serviceError =
       dtoFactory.createDtoFromJson(error.getMessage(), ServiceError.class);
   notificationManager.notify(serviceError.getMessage(), FAIL, true);
   view.showError(serviceError.getMessage());
 }
  @Override
  public void onDeployClicked() {
    Promise<Project> projectPromise;
    view.showLoader(true);
    switch (view.getMode()) {
      case CREATE_NEW_PROJECT:
        String osProjectName = view.getOpenShiftProjectName();
        String osProjectDisplayName = view.getOpenShiftProjectDisplayName();
        String osProjectDescription = view.getOpenShiftProjectDescription();
        // create new project
        ProjectRequest request =
            newDto(ProjectRequest.class)
                .withApiVersion(API_VERSION)
                .withDisplayName(osProjectDisplayName)
                .withDescription(osProjectDescription)
                .withMetadata(newDto(ObjectMeta.class).withName(osProjectName));
        projectPromise = osService.createProject(request);
        break;
      case SELECT_EXISTING_PROJECT:
      default:
        Project osSelectedProject = view.getOpenShiftSelectedProject();
        projectPromise = Promises.resolve(osSelectedProject);
    }

    projectPromise
        .then(
            new Operation<Project>() {
              @Override
              public void apply(final Project project) throws OperationException {
                final Map<String, String> labels = new HashMap<>();
                labels.put("generatedby", "Che");
                labels.put("application", osAppName);

                for (KeyValue label : view.getLabels()) {
                  labels.put(label.getKey(), label.getValue());
                }

                final DockerImageMetadata imageMetadata =
                    osActiveStreamTag.getImage().getDockerImageMetadata();
                Object exposedPorts =
                    (imageMetadata.getConfig() != null)
                        ? imageMetadata.getConfig().getExposedPorts()
                        : imageMetadata.getContainerConfig().getExposedPorts();
                List<ContainerPort> ports = parsePorts(exposedPorts);

                String namespace = project.getMetadata().getName();
                List<Promise<?>> promises = new ArrayList<>();
                promises.add(osService.createImageStream(generateImageStream(namespace, labels)));
                promises.add(osService.createBuildConfig(generateBuildConfig(namespace, labels)));
                promises.add(
                    osService.createDeploymentConfig(generateDeploymentConfig(namespace, labels)));
                promises.add(osService.createRoute(generateRoute(namespace, labels)));

                if (!ports.isEmpty()) {
                  promises.add(
                      osService.createService(
                          generateService(namespace, getFirstPort(ports), labels)));
                }

                Promises.all(promises.toArray(new Promise[promises.size()]))
                    .then(
                        new Operation<JsArrayMixed>() {
                          @Override
                          public void apply(JsArrayMixed arg) throws OperationException {
                            view.showLoader(false);
                            view.hide();
                            notificationManager.notify(
                                locale.deployProjectSuccess(
                                    appContext.getCurrentProject().getRootProject().getName()),
                                SUCCESS,
                                true);
                            setupMixin(project);
                          }
                        })
                    .catchError(
                        new Operation<PromiseError>() {
                          @Override
                          public void apply(PromiseError arg) throws OperationException {
                            handleError(arg);
                          }
                        });
              }
            })
        .catchError(
            new Operation<PromiseError>() {
              @Override
              public void apply(PromiseError arg) throws OperationException {
                handleError(arg);
              }
            });
  }