Esempio n. 1
0
  public String insertAndStartRun(String messageBody)
      throws UnsupportedSerializationFormatException, SerializationException {

    try {
      Request requestMessageObject =
          new XMLDeserializer().getObjectFromMessage(messageBody, Request.class);
      RequestMeta meta = requestMessageObject.getRequestMeta();
      ObjectSerializationInformation config = meta.getRequestBodySerializationInformation();

      SerializationFormat format = config.getFormat();
      Deserializer deserializer = DeserializerFactory.getDeserializer(format);

      String className = config.getClassName();
      String classNamespace = config.getClassNameSpace();

      RunMessage object =
          (RunMessage)
              deserializer.getObjectFromMessage(
                  requestMessageObject.getRequestBody(), className, classNamespace);

      RunResult runResult;
      if (object instanceof RunSimulationMessage) {
        runResult = impl.runSimulation((RunSimulationMessage) object);
      } else if (object instanceof RunSimulationsMessage) {
        runResult = impl.runSimulations((RunSimulationsMessage) object);
      } else if (object instanceof RunVisualizationMessage) {
        runResult = impl.runVisualization((RunVisualizationMessage) object);
      } else {
        responseBuilder.setStatus(
            HttpStatus.BAD_REQUEST,
            "The object in the message body was not an instance of a valid run message type. "
                + "The valid types are: RunSimulationMessage, RunSimulationsMessage, RunVisualizationMessage");
        return serializer.serializeObject(responseBuilder.getResponse());
      }

      InsertRunResult insertRunResult = new InsertRunResult();
      insertRunResult.setRunId(runResult.getRunId());

      ObjectSerializationInformation objectSerializationInformation =
          new ObjectSerializationInformation();
      objectSerializationInformation.setClassNameSpace(Serializer.SERVICES_COMMON_NAMESPACE);
      objectSerializationInformation.setClassName(insertRunResult.getClass().getSimpleName());
      objectSerializationInformation.setFormat(SerializationFormat.XML);

      String serializedObject = serializer.serializeObject(runResult);
      responseBuilder
          .setResponseBodySerializationInformation(objectSerializationInformation)
          .addContentToBody(serializedObject)
          .setIsBodySerialized(true);
      responseBuilder.setStatus(HttpStatus.OK, ResponseMessageBuilder.DEFAULT_SUCCESS_MESSAGE);

    } catch (DeserializationException | UnsupportedSerializationFormatException ex) {
      responseBuilder.setStatus(HttpStatus.OK, ex.getMessage());
    }

    return serializer.serializeObject(responseBuilder.getResponse());
  }
Esempio n. 2
0
  public String addRole(String messageBody)
      throws UnsupportedSerializationFormatException, SerializationException {

    try {
      Request requestMessageObject =
          new XMLDeserializer().getObjectFromMessage(messageBody, Request.class);
      RequestMeta meta = requestMessageObject.getRequestMeta();
      ObjectSerializationInformation config = meta.getRequestBodySerializationInformation();

      SerializationFormat format = config.getFormat();
      Deserializer deserializer = DeserializerFactory.getDeserializer(format);

      String className = config.getClassName();
      String classNamespace = config.getClassNameSpace();

      Object object = deserializer.getObjectFromMessage(messageBody, className, classNamespace);

      if (!(object instanceof AddRoleMessage)) {
        responseBuilder.setStatus(
            HttpStatus.BAD_REQUEST,
            "The object in the message body was not an instance of AddRoleMessage");
      } else {
        AddRoleMessage message = (AddRoleMessage) object;

        SoftwareIdentification softwareId = message.getSoftwareIdentification();
        boolean canRunSoftware = message.isCanRun();
        boolean canRequestPrivileged = message.isCanRequestPrivileged();
        String roleDescription = message.getRoleDescription();

        try {
          impl.addRole(
              softwareId, canRunSoftware, canRequestPrivileged, roleDescription, authentication);

          responseBuilder.setStatus(HttpStatus.OK, ResponseMessageBuilder.DEFAULT_SUCCESS_MESSAGE);
        } catch (DataServiceException ex) {
          responseBuilder.setStatus(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
        }
      }
    } catch (DeserializationException | UnsupportedSerializationFormatException ex) {
      responseBuilder.setStatus(HttpStatus.OK, ex.getMessage());
    }

    return serializer.serializeObject(responseBuilder.getResponse());
  }