Ejemplo n.º 1
0
  @POST
  @Produces(JSON_UTF8)
  @Path("disconnectMissionProcess")
  public Response disconnectMissionProcess(
      @QueryParam("processNumber") String processNumber,
      @QueryParam("hostname") String hostname,
      @QueryParam("remoteProcessNumber") String remoteProcessNumber,
      @QueryParam("username") String username,
      @QueryParam("access_token") String access_token) {

    checkToken(access_token);
    login(User.findByUsername(username));
    try {
      final Mission mission = findMission(remoteProcessNumber);
      if (mission == null) {
        return respondWithError(Status.BAD_REQUEST, "bad.mission.number");
      } else {
        final MissionProcess missionProcess = mission.getMissionProcess();

        final RemoteMissionSystem remoteMissionSystem = RemoteMissionSystem.find(hostname);
        if (remoteMissionSystem == null) {
          return respondWithError(Status.NOT_ACCEPTABLE, "remote.host.not.configured");
        }

        for (final RemoteMissionProcess remoteMissionProcess :
            missionProcess.getRemoteMissionProcessSet()) {
          if (remoteMissionProcess.getRemoteMissionSystem() == remoteMissionSystem
              && remoteMissionProcess.getProcessNumber().equals(processNumber)) {
            final DisassociateMissionProcessActivity activity =
                (DisassociateMissionProcessActivity)
                    missionProcess.getActivity(DisassociateMissionProcessActivity.class);
            final DisassociateMissionProcessActivityInfo information =
                activity.getActivityInformation(missionProcess);
            information.setRemoteMissionProcess(remoteMissionProcess);
            information.setConnect(false);
            activity.execute(information);
          }
        }

        return Response.ok().build();
      }
    } finally {
      logout();
    }
  }
Ejemplo n.º 2
0
  @POST
  @Produces(JSON_UTF8)
  @Path("connectMissionProcess")
  public Response connectMissionProcess(
      @QueryParam("processNumber") String processNumber,
      @QueryParam("externalId") String externalId,
      @QueryParam("hostname") String hostname,
      @QueryParam("remoteProcessNumber") String remoteProcessNumber,
      @QueryParam("username") String username,
      @QueryParam("access_token") String access_token) {

    checkToken(access_token);
    try {
      login(User.findByUsername(username));
      final Mission mission = findMission(remoteProcessNumber);
      if (mission == null) {
        return respondWithError(Status.BAD_REQUEST, "bad.mission.number");
      } else {
        final MissionProcess missionProcess = mission.getMissionProcess();

        final RemoteMissionSystem remoteMissionSystem = RemoteMissionSystem.find(hostname);
        if (remoteMissionSystem == null) {
          return respondWithError(Status.NOT_ACCEPTABLE, "remote.host.not.configured");
        }

        final AssociateMissionProcessActivity activity =
            (AssociateMissionProcessActivity)
                missionProcess.getActivity(AssociateMissionProcessActivity.class);
        final AssociateMissionProcessActivityInfo information =
            activity.getActivityInformation(missionProcess);
        information.setProcessNumber(processNumber);
        information.setExternalId(externalId);
        information.setRemoteMissionSystem(remoteMissionSystem);
        information.setConnect(false);
        activity.execute(information);

        final JsonObject obj = new JsonObject();
        obj.addProperty("processID", missionProcess.getProcessNumber());
        obj.addProperty("externalId", missionProcess.getExternalId());
        return Response.ok().entity(gson.toJson(obj)).build();
      }
    } finally {
      logout();
    }
  }