public int compare(Object o1, Object o2) throws ClassCastException {
    if (!(o1 instanceof ServiceInvocationInfo)) {
      throw new ClassCastException(
          ServerResourceBundle.getInstance()
              .getString("message.objectNotServiceInvocationInfo", new Object[] {o1}));
    }

    if (!(o2 instanceof ServiceInvocationInfo)) {
      throw new ClassCastException(
          ServerResourceBundle.getInstance()
              .getString("message.objectNotServiceInvocationInfo", new Object[] {o2}));
    }

    ServiceInvocationInfo si1 = (ServiceInvocationInfo) o1;
    ServiceInvocationInfo si2 = (ServiceInvocationInfo) o2;

    int result = 0;
    int serviceResult = identifiableComparator.compare(si1.getService(), si2.getService());

    if (serviceResult != 0) {
      result = serviceResult;
    } else {
      // TODO: This should at least compare on IDs of extrinsic
      // objects representing control files.
      result = 1;
    }

    return result;
  }
  /**
   * Returns the SQL fragment string needed by insert or update statements within insert or update
   * method of sub-classes. This is done to avoid code duplication.
   */
  protected String getSQLStatementFragment(Object object) throws RegistryException {
    // object must be an ObjectRef for an objects affected by parent event
    ObjectRefType affectedObject = (ObjectRefType) object;

    String stmtFragment = null;

    String id = affectedObject.getId();
    String home = affectedObject.getHome();

    if (home != null) {
      home = "'" + home + "'";
    }

    String eventId = ((AuditableEventType) parent).getId();

    if (action == DAO_ACTION_INSERT) {
      stmtFragment =
          "INSERT INTO AffectedObject VALUES("
              + " '"
              + id
              + "', "
              + home
              + ", '"
              + eventId
              + "' ) ";
    } else if (action == DAO_ACTION_UPDATE) {
      throw new RegistryException(
          ServerResourceBundle.getInstance().getString("message.cannotUpdateComposedObject"));
    } else if (action == DAO_ACTION_DELETE) {
      stmtFragment = super.getSQLStatementFragment(object);
    }

    return stmtFragment;
  }
Beispiel #3
0
  // TODO: Move to a utility class as there is also another copy in AzImpl
  private String getUserInfo(UserType user) {
    String idStr = user.getId();
    String userInfo;

    try {
      PersonNameImpl personName = new PersonNameImpl(null, null, user.getPersonName());
      userInfo =
          ServerResourceBundle.getInstance()
              .getString("message.idName", new String[] {idStr, personName.getFormattedName()});
    } catch (Exception e) {
      log.warn(e.toString(), e);

      // problem with the formatted name, fall back to id alone
      userInfo = ServerResourceBundle.getInstance().getString("message.id", new String[] {idStr});
    }

    return userInfo;
  }
 private String getSelectColumn() throws RegistryException {
   if (parentQueryProcessor == null) {
     return "*";
   } else {
     if (foreignKeyColumn == null) {
       throw new RegistryException(
           ServerResourceBundle.getInstance().getString("message.foreignKeyColumnNotSet"));
     }
     return foreignKeyColumn;
   }
 }
  protected void loadObject(Object obj, ResultSet rs) throws RegistryException {
    try {
      if (!(obj instanceof org.oasis.ebxml.registry.bindings.rim.ObjectRefType)) {
        throw new RegistryException(
            ServerResourceBundle.getInstance()
                .getString("message.ObjectRefTypeExpected", new Object[] {obj}));
      }

      ObjectRefType ro = (ObjectRefType) obj;
      ro.setId(rs.getString("id"));

      String home = rs.getString("home");
      if (home != null) {
        ro.setHome(home);
      }

    } catch (SQLException e) {
      log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e);
      throw new RegistryException(e);
    }
  }
Beispiel #6
0
  private String transformContent(
      ServerRequestContext context, String xsltId, String xmlNotif, String action, String user)
      throws RegistryException {
    try {
      RepositoryItem repositoryItem =
          RepositoryManagerFactory.getInstance().getRepositoryManager().getRepositoryItem(xsltId);
      StreamSource xsltIn = new StreamSource(repositoryItem.getDataHandler().getInputStream());

      TransformerFactory tFactory = TransformerFactory.newInstance();
      Transformer transformer = tFactory.newTransformer(xsltIn);

      // transformer.setURIResolver(rm.getURIResolver());
      transformer.setErrorListener(
          new ErrorListener() {
            public void error(TransformerException exception) throws TransformerException {
              log.info(ServerResourceBundle.getInstance().getString("xsltError"), exception);
            }

            public void fatalError(TransformerException exception) throws TransformerException {
              log.error(ServerResourceBundle.getInstance().getString("xsltFatalError"), exception);
              throw exception;
            }

            public void warning(TransformerException exception) throws TransformerException {
              log.info(ServerResourceBundle.getInstance().getString("xsltWarning"), exception);
            }
          });

      // Set parameters
      transformer.setParameter("action", action);
      transformer.setParameter("user", user);
      transformer.setParameter(
          "registryBaseURL", RegistryProperties.getInstance().getProperty("omar.registry.baseurl"));

      ByteArrayInputStream bais = new ByteArrayInputStream(xmlNotif.getBytes("utf-8"));
      StreamSource inputSrc = new StreamSource(bais);

      // TODO: use file in case we have a large amount of data to transform?
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      StreamResult streamResult = new StreamResult(baos);

      transformer.transform(inputSrc, streamResult);

      return baos.toString("utf-8");
    } catch (Exception e) {
      log.error(
          ServerResourceBundle.getInstance().getString("message.prettyPrintNotificationFailure"),
          e);
      throw new RegistryException(e);
    }
  }
  /**
   * Extends 'evalArgs' to check for required parameters.
   *
   * @param params
   * @param context
   * @param args
   * @param minParams Minimal number of parameters in 'params'.
   * @return EvaluationResult if something is wrong. Null otherwise.
   */
  protected EvaluationResult evalArgs(
      List params, EvaluationCtx context, AttributeValue[] args, int minParams) {
    EvaluationResult result = super.evalArgs(params, context, args);

    if (result == null) {
      if (params.size() < minParams) {

        // Check which arguments are missing
        StringBuffer sb = new StringBuffer();
        for (int i = params.size(); i < minParams; i++) {
          sb.append(
              ServerResourceBundle.getInstance()
                  .getString(
                      "message.xacmlExtFunctionParamMissing",
                      new Object[] {
                        getFunctionName(), getParameterNames()[i], String.valueOf(i + 1)
                      }));
          if (i + 1 < minParams) {
            sb.append(" ");
          }
        }

        // Use an Exception to log
        RegistryException e = new RegistryException(sb.toString());
        log.error(
            ServerResourceBundle.getInstance()
                .getString("message.xacmlExtFunctionEvalError", new Object[] {getFunctionName()}),
            e);

        // Return EvaluationResult with missing attribute code
        List codes = new ArrayList();
        codes.add(Status.STATUS_MISSING_ATTRIBUTE);
        result = new EvaluationResult(new Status(codes, e.getMessage()));
      }
    }

    return result;
  }
  public void checkRegistryObjectLid(RegistryObjectType ro) throws RegistryException {
    String id = ro.getId();
    String lid = ro.getLid();

    String existingObjectLid = (String) context.getIdToLidMap().get(id);

    // Assign lid if not specified, validate lid if specified
    if (existingObjectLid != null) {
      if (lid == null) {
        ro.setLid(existingObjectLid);
      } else {
        // Validate that lid matches existing objects lid
        if (!lid.equals(existingObjectLid)) {
          throw new RegistryException(
              ServerResourceBundle.getInstance()
                  .getString("message.idDoesNotMatch", new Object[] {lid, existingObjectLid, id}));
        }
      }
    } else {
      checkRegistryObjectLidOnNewObject(ro);
    }
  }
  private String nextVersion(String lastVersion) {
    if ((lastVersion == null) || (lastVersion.length() == 0)) {
      lastVersion = "1.1";
    }

    String parts[] = lastVersion.split("\\.", 3);
    int majorVersion = (new Integer(parts[0])).intValue();
    int minorVersion = (new Integer(parts[1])).intValue();

    // TODO: check this. What if version has more than major/minor?
    if (parts.length > 2 && log.isWarnEnabled()) {
      log.warn(
          ServerResourceBundle.getInstance()
              .getString(
                  "message.IgnoringVersionInfromationAfterMajorMinorVersion",
                  new Object[] {parts[2]}));
    }

    // Increment version
    int newMinorVersion = minorVersion + 1;

    String nextVersion = parts[0] + "." + (new Integer(newMinorVersion)).toString();
    return nextVersion;
  }
Beispiel #10
0
  protected void sendNotification(
      ServerRequestContext context,
      NotifyActionType notifyAction,
      NotificationType notification,
      AuditableEventType ae)
      throws RegistryException {
    log.trace("Sending email notification");

    String endpoint = notifyAction.getEndPoint();

    if ((endpoint == null) || !endpoint.startsWith("mailto:")) {
      throw new RegistryException(
          ServerResourceBundle.getInstance()
              .getString("message.emailNotificationWOmailto", new Object[] {endpoint}));
    }

    try {
      // get the body of the message , not yet defined !
      StringWriter sw = new StringWriter();
      Marshaller marshaller = BindingUtility.getInstance().rimFac.createMarshaller();
      marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
      marshaller.marshal(notification, sw);

      // Now get the RegistryResponse as a String

      // Produce verbose response
      String notif = sw.toString();
      String action = ae.getEventType();
      String userId = ae.getUser();

      String userInfo;
      if (userId != null) {
        UserType user = (UserType) context.getRegistryObject(userId, "User_");
        userInfo =
            ServerResourceBundle.getInstance()
                .getString("message.user", new String[] {getUserInfo(user)});
      } else {
        userInfo = ServerResourceBundle.getInstance().getString("message.userUnknown");
      }

      SubscriptionType subscription =
          (SubscriptionType)
              context.getRegistryObject(notification.getSubscription(), "Subscription");
      String xsltId = getStyleSheetId(subscription);
      RepositoryItem repositoryItem = null;

      // empty string for notification property == use old format
      if (!"".equals(xsltId)) {
        // Dont use transform if there are any problems
        try {
          repositoryItem =
              RepositoryManagerFactory.getInstance()
                  .getRepositoryManager()
                  .getRepositoryItem(xsltId);
        } catch (Exception e) {
          log.warn(ServerResourceBundle.getInstance().getString("message.rawEmailNotification"), e);
        }
      }

      String contentType;
      String message;
      if (repositoryItem == null) {
        // No style sheet so skip the tranformation
        contentType = "text/xml";
        message = sw.toString();
      } else {
        contentType = "text/html";
        try {
          message = transformContent(context, xsltId, notif, action, userInfo);
        } catch (RegistryException e) {
          contentType = "text/xml";
          message = sw.toString();
        }
      }

      // set parameters and send the mail
      String subject =
          ServerResourceBundle.getInstance()
              .getString("message.registryNotification", new Object[] {notification.getId()});
      postMail(endpoint, message, subject, contentType);
    } catch (MessagingException e) {
      throw new RegistryException(e);
    } catch (JAXBException e) {
      throw new RegistryException(e);
    }
  }