コード例 #1
0
  /*
   * Appends a new predicate to an old predicate using an AND logical operator between them
   * and uses the specified relationshipPred to constrain the newPred.
   *
   * Handles case where old or new predicate is non-existent (white spaces only).
   *
   */
  protected String appendPredicate(String oldPred, String newPred, String relationshipPred) {
    if (!(Utility.containsWhiteSpacesOnly(newPred))) {
      if (!(Utility.containsWhiteSpacesOnly(relationshipPred))) {
        newPred = "(" + relationshipPred + "AND " + newPred + ") ";
      }

      if (!(Utility.containsWhiteSpacesOnly(oldPred))) {
        oldPred += "AND ";
      }
      oldPred += newPred;
    }

    return oldPred;
  }
コード例 #2
0
  /*
   * Appends a new predicate to an old predicate using an AND logical operator between them
   * and used the default joinPred to constrain the newPred.
   * Handles case where old or new predicate is non-existent (white spaces only).
   *
   */
  protected String appendPredicate(String oldPred, String newPred) {
    if (!(Utility.containsWhiteSpacesOnly(newPred))) {
      String joinPred = getJoinPredicate();

      oldPred = appendPredicate(oldPred, newPred, joinPred);
    }

    return oldPred;
  }
コード例 #3
0
  /** Gets the RIM class name that matches this QueryProcessor. */
  private String getRIMClassName() {
    String name = Utility.getInstance().getClassNameNoPackage(this);
    // Remove "QueryProcessor" suffix
    if (name.endsWith("QueryProcessor")) {
      name = name.substring(0, name.length() - 14);
    }
    // Remove "BranchProcessor" suffix
    if (name.endsWith("BranchProcessor")) {
      name = name.substring(0, name.length() - 15);
    }

    return name;
  }
コード例 #4
0
  private String buildWhereClause() throws RegistryException {
    String whereClause = "";
    String filterPredicate = processFilters();
    String branchPredicate = processBranches();
    String subQueryPredicate = processSubQueries();

    if (!(Utility.containsWhiteSpacesOnly(filterPredicate))) {
      whereClause += filterPredicate;
    }

    whereClause = appendPredicate(whereClause, branchPredicate);
    whereClause = appendPredicate(whereClause, subQueryPredicate);

    // Only add "WHERE" if if top level FilterQueryProcessor (has no parent) AND
    // there are non-white-space characters in whereClause
    if (parentQueryProcessor == null) {
      if (!(Utility.containsWhiteSpacesOnly(whereClause))) {
        whereClause = " WHERE " + whereClause;
      }
    }
    return whereClause;
  }
コード例 #5
0
  /** Convert the specified FilterQueryType instance to an equivalent SQL query string. */
  public String process() throws RegistryException {
    String sqlQuery = null;
    String tableName = Utility.getInstance().mapTableName(getRIMClassName());
    if (alias == null) {
      alias = getAliasForTable(tableName);
    }

    // Generate the "WHERE" clause for query which may have nested SELECTS etc.
    String whereClause = buildWhereClause();

    // Generate the initial part of query of form "SELECT tbl.* FROM <tablename> tbl"
    sqlQuery = buildSelectStatement();

    if (whereClause != null) {
      sqlQuery += whereClause;
    }

    return sqlQuery;
  }
コード例 #6
0
  static FilterQueryProcessor newInstance(
      FilterQueryProcessor parentQueryProcessor, FilterQueryType filterQuery)
      throws RegistryException {
    FilterQueryProcessor filterQueryProcessor = null;
    String className = Utility.getInstance().getClassNameNoPackage(filterQuery);
    if (className.endsWith("Impl")) {
      className = className.substring(0, className.length() - 4); // Remove Impl suffix.
    }
    if (className.endsWith("Type")) {
      className = className.substring(0, className.length() - 4); // Remove Type suffix.
    }
    className = "org.freebxml.omar.server.query.filter." + className + "Processor";

    try {
      Class filterQueryProcessorClass = Class.forName(className);

      Class[] parameterTypes = new Class[2];
      parameterTypes[0] = FilterQueryProcessor.class;
      parameterTypes[1] = FilterQueryType.class;
      Constructor constructor = filterQueryProcessorClass.getConstructor(parameterTypes);

      Object[] parameterValues = new Object[2];
      parameterValues[0] = parentQueryProcessor;
      parameterValues[1] = filterQuery;
      filterQueryProcessor = (FilterQueryProcessor) constructor.newInstance(parameterValues);
    } catch (ClassNotFoundException e) {
      throw new RegistryException(e);
    } catch (NoSuchMethodException e) {
      throw new RegistryException(e);
    } catch (IllegalArgumentException e) {
      throw new RegistryException(e);
    } catch (IllegalAccessException e) {
      throw new RegistryException(e);
    } catch (InvocationTargetException e) {
      throw new RegistryException(e);
    } catch (ExceptionInInitializerError e) {
      throw new RegistryException(e);
    } catch (InstantiationException e) {
      throw new RegistryException(e);
    }

    return filterQueryProcessor;
  }
コード例 #7
0
ファイル: AdminToolTest.java プロジェクト: Gaduo/omar.tcumi
  public void testAddUser() throws Exception {
    String id = org.freebxml.omar.common.Utility.getInstance().createId();

    // add user -fn ble -ln bla -alias blablak -email [email protected]
    String[] args = {
      "-verbose",
      "-command",
      "add user -fn "
          + id
          + " -ln "
          + id
          + " -alias  "
          + id
          + " -keypass "
          + id
          + " -org someOrg -orgunit someOrgUnit -email [email protected]"
    };

    AdminTool adminTool = new AdminTool();
    adminTool.run(args, System.in, System.out);
  }
コード例 #8
0
  private List getAllRegistryObjectVersions(RegistryObjectType ro) throws RegistryException {
    if (versions == null) {
      ServerRequestContext queryContext = null;

      // Note: ORDER BY versionName DESC is not safe because String(1.10) < String(1.9)
      String query =
          "SELECT ro.* FROM "
              + Utility.getInstance().mapTableName(ro)
              + " ro WHERE ro.lid = '"
              + ro.getLid()
              + "'";

      try {
        AdhocQueryRequest queryRequest = bu.createAdhocQueryRequest(query);
        queryContext =
            new ServerRequestContext("VersionProcessor.getAllRegistryObjectVersions", queryRequest);

        queryContext.setUser(ac.registryOperator);

        AdhocQueryResponseType queryResp = qm.submitAdhocQuery(queryContext);
        versions = queryResp.getRegistryObjectList().getIdentifiable();
        queryContext.commit();
        queryContext = null;
      } catch (JAXBException e) {
        throw (new RegistryException(e));
      } catch (JAXRException e) {
        throw (new RegistryException(e));
      } finally {
        if (queryContext != null) {
          queryContext.rollback();
        }
      }
    }

    return (versions);
  }
コード例 #9
0
ファイル: AssociationTest.java プロジェクト: Gaduo/omar.tcumi
  public void testSaveUnownedAssociations() throws Exception {

    String folderId = null;
    String farrukhExtrinsicObjectId = null;
    String farrukhAssociationId = null;
    String nikolaExtrinsicObjectId = null;
    String nikolaAssociationId = null;

    String keystorePath =
        RegistryProperties.getInstance().getProperty("omar.security.keystoreFile");
    String storepass =
        RegistryProperties.getInstance().getProperty("omar.security.keystorePassword");

    ConnectionFactory connFactory = JAXRUtility.getConnectionFactory();
    Properties props = new Properties();
    props.put("javax.xml.registry.queryManagerURL", regSoapUrl);
    connFactory.setProperties(props);

    try {

      // create connection for Farrukh

      Connection farrukhConnection = connFactory.createConnection();
      String farrukhAlias = "urn:freebxml:registry:predefinedusers:registryoperator";
      Set farrukhCredentials =
          getCredentialsFromKeystore(keystorePath, storepass, farrukhAlias, farrukhAlias);
      farrukhConnection.setCredentials(farrukhCredentials);
      BusinessQueryManagerImpl farrukhBQM =
          (BusinessQueryManagerImpl)
              farrukhConnection.getRegistryService().getBusinessQueryManager();
      LifeCycleManager farrukhLCM =
          farrukhConnection.getRegistryService().getBusinessLifeCycleManager();

      // Create the folder as Farrukh

      RegistryPackage folder = farrukhLCM.createRegistryPackage("Farrukh's Folder");
      folderId = folder.getKey().getId();
      System.out.println("Created folder with id '" + folderId + "'");

      // using farrukh's connection, saveObjects() with extrinsic object and hasMember association
      File file = createTempFile(true);
      FileDataSource fds = new FileDataSource(file);
      DataHandler dataHandler = new DataHandler(fds);
      ExtrinsicObject farrukhExtrinsicObject =
          (ExtrinsicObject) farrukhLCM.createExtrinsicObject(dataHandler);
      String eoId = Utility.getInstance().createId();
      farrukhExtrinsicObject.getKey().setId(eoId);
      farrukhExtrinsicObject.setName(
          farrukhLCM.createInternationalString("Farrukh's Extrinsic Object"));

      Concept associationConcept =
          farrukhBQM.findConceptByPath(
              "/"
                  + BindingUtility.CANONICAL_CLASSIFICATION_SCHEME_LID_AssociationType
                  + "/"
                  + BindingUtility.CANONICAL_ASSOCIATION_TYPE_CODE_HasMember);
      Association farrukhAssociation =
          farrukhLCM.createAssociation(farrukhExtrinsicObject, associationConcept);
      farrukhAssociation.setSourceObject(folder);

      ArrayList objectsToSave = new ArrayList();
      objectsToSave.add(folder);
      objectsToSave.add(farrukhAssociation);
      objectsToSave.add(farrukhExtrinsicObject);
      System.out.println(
          "Saving farrukh's extrinsic object '"
              + farrukhExtrinsicObject.getKey().getId()
              + "' under folder '"
              + folderId
              + "' with hasMember association '"
              + farrukhAssociation.getKey().getId()
              + "'");
      BulkResponse br = farrukhLCM.saveObjects(objectsToSave);
      JAXRUtility.checkBulkResponse(br);
      farrukhExtrinsicObjectId = farrukhExtrinsicObject.getKey().getId();
      farrukhAssociationId = farrukhAssociation.getKey().getId();
      System.out.println(
          "Objects '"
              + farrukhExtrinsicObject.getKey().getId()
              + "' and '"
              + farrukhAssociation.getKey().getId()
              + "' saved successfully");

      // create connection for Nikola

      Connection nikolaConnection = connFactory.createConnection();
      String nikolaAlias = "urn:freebxml:registry:predefinedusers:nikola";
      Set nikolaCredentials =
          getCredentialsFromKeystore(keystorePath, storepass, nikolaAlias, nikolaAlias);
      nikolaConnection.setCredentials(nikolaCredentials);
      BusinessQueryManagerImpl nikolaBQM =
          (BusinessQueryManagerImpl)
              nikolaConnection.getRegistryService().getBusinessQueryManager();
      LifeCycleManager nikolaLCM =
          nikolaConnection.getRegistryService().getBusinessLifeCycleManager();

      // Get the folder

      /*RegistryPackage*/ folder = (RegistryPackage) nikolaBQM.getRegistryObject(folderId);
      Assert.assertNotNull("Could not find root folder", folder);

      // using nikola's connection, saveObjects() with extrinsic object and hasMember association
      file = createTempFile(true);
      fds = new FileDataSource(file);
      dataHandler = new DataHandler(fds);
      ExtrinsicObject nikolaExtrinsicObject =
          (ExtrinsicObject) nikolaLCM.createExtrinsicObject(dataHandler);
      eoId = Utility.getInstance().createId();
      nikolaExtrinsicObject.getKey().setId(eoId);
      nikolaExtrinsicObject.setName(
          nikolaLCM.createInternationalString("Nikola's Extrinsic Object"));

      associationConcept =
          nikolaBQM.findConceptByPath(
              "/"
                  + BindingUtility.CANONICAL_CLASSIFICATION_SCHEME_LID_AssociationType
                  + "/"
                  + BindingUtility.CANONICAL_ASSOCIATION_TYPE_CODE_HasMember);
      Association nikolaAssociation =
          nikolaLCM.createAssociation(nikolaExtrinsicObject, associationConcept);
      nikolaAssociation.setSourceObject(folder);

      objectsToSave = new ArrayList();
      objectsToSave.add(folder);
      objectsToSave.add(nikolaAssociation);
      System.out.println(
          "Saving nikola's extrinsic object '"
              + nikolaExtrinsicObject.getKey().getId()
              + "' under folder '"
              + folderId
              + "' with hasMember association '"
              + nikolaAssociation.getKey().getId()
              + "'");
      objectsToSave.add(nikolaExtrinsicObject);
      br = nikolaLCM.saveObjects(objectsToSave);
      JAXRUtility.checkBulkResponse(br);
      nikolaExtrinsicObjectId = nikolaExtrinsicObject.getKey().getId();
      nikolaAssociationId = nikolaAssociation.getKey().getId();
      System.out.println(
          "Objects '"
              + nikolaExtrinsicObject.getKey().getId()
              + "' and '"
              + nikolaAssociation.getKey().getId()
              + "' saved successfully");
    } finally {
      // remove extrinsic objects and associations as registry operator
      try {
        Connection roConnection = connFactory.createConnection();
        String roAlias = "urn:freebxml:registry:predefinedusers:registryoperator";
        Set roCredentials = getCredentialsFromKeystore(keystorePath, storepass, roAlias, roAlias);
        roConnection.setCredentials(roCredentials);
        LifeCycleManagerImpl roLCM =
            (LifeCycleManagerImpl) roConnection.getRegistryService().getBusinessLifeCycleManager();

        if (folderId != null) {
          System.out.println("Deleting '" + folderId + "'");
          HashSet keys = new HashSet();
          keys.add(roLCM.createKey(folderId));
          roLCM.deleteObjects(keys, null, forceRemoveRequestSlotsMap, null);
          System.out.println("Successfully deleted '" + folderId + "'");
        }

        if (farrukhExtrinsicObjectId != null) {
          System.out.println("Deleting '" + farrukhExtrinsicObjectId + "'");
          HashSet keys = new HashSet();
          keys.add(roLCM.createKey(farrukhExtrinsicObjectId));
          roLCM.deleteObjects(keys, null, forceRemoveRequestSlotsMap, null);
          System.out.println("Successfully deleted '" + farrukhExtrinsicObjectId + "'");
        }

        if (farrukhAssociationId != null) {
          System.out.println("Deleting '" + farrukhAssociationId + "'");
          HashSet keys = new HashSet();
          keys.add(roLCM.createKey(farrukhAssociationId));
          roLCM.deleteObjects(keys, null, forceRemoveRequestSlotsMap, null);
          System.out.println("Successfully deleted '" + farrukhAssociationId + "'");
        }

        if (nikolaExtrinsicObjectId != null) {
          System.out.println("Deleting '" + nikolaExtrinsicObjectId + "'");
          HashSet keys = new HashSet();
          keys.add(roLCM.createKey(nikolaExtrinsicObjectId));
          roLCM.deleteObjects(keys, null, forceRemoveRequestSlotsMap, null);
          System.out.println("Successfully deleted '" + nikolaExtrinsicObjectId + "'");
        }

        if (nikolaAssociationId != null) {
          System.out.println("Deleting '" + nikolaAssociationId + "'");
          HashSet keys = new HashSet();
          keys.add(roLCM.createKey(nikolaAssociationId));
          roLCM.deleteObjects(keys, null, forceRemoveRequestSlotsMap, null);
          System.out.println("Successfully deleted '" + nikolaAssociationId + "'");
        }

      } catch (Throwable t) {
        System.err.println(
            "Failed to remove some or all of the test objects. Exception: " + t.getMessage());
        t.printStackTrace();
      }
    }
  }
コード例 #10
0
  public RegistryObjectType createRegistryObjectVersion(RegistryObjectType ro)
      throws RegistryException {
    RegistryObjectType roNew = null;

    try {
      Utility util = Utility.getInstance();

      RegistryObjectType lastVersion = getLatestVersionOfRegistryObject(ro);
      String nextVersion = null;
      if (lastVersion == null) {
        nextVersion = "1.1";
      } else {
        nextVersion = nextVersion(lastVersion.getVersionInfo().getVersionName());
      }

      roNew = bu.cloneRegistryObject(ro);
      VersionInfoType nextVersionInfo = bu.rimFac.createVersionInfoType();
      nextVersionInfo.setVersionName(nextVersion);

      // Set the comment from the request comment (per the spec)
      if (!context.getRegistryRequestStack().empty()) {
        nextVersionInfo.setComment(context.getCurrentRegistryRequest().getComment());
      }

      roNew.setVersionInfo(nextVersionInfo);

      // A new version must have a unique id
      String id = ro.getId();
      String lid = ro.getLid();
      String idNew = id;

      // Only change id if it already exists in versions
      // Need to preserve client supplied id in the case where lid is an
      // existing lid but id is new
      if (isIdInVersions(id)) {
        // Make id of next version be lid with ":nextVersion" as suffix, if this id is already in
        // use in a version
        idNew = lid + ":" + nextVersion; // Utility.getInstance().createId();
        roNew.setId(idNew);

        // Add entry to idMap so old id and refs to it are mapped to idNew
        context.getIdMap().put(id, idNew);
      }

      // Add entry to context.newROVersionMap for later replacement
      context.getNewROVersionMap().put(ro, roNew);

      // Assign new ids to all composed RegistryObjects within roNew
      Set composedObjects = bu.getComposedRegistryObjects(roNew, -1);

      Iterator iter = composedObjects.iterator();
      while (iter.hasNext()) {
        RegistryObjectType composedObject = (RegistryObjectType) iter.next();

        // check for composed object if exist change the id and lid and
        // also update the idMap.
        if (objectExists(composedObject.getId())) {
          String oldId = composedObject.getId();
          String newId = oldId + ":" + nextVersion;
          composedObject.setId(newId);
          composedObject.setLid(newId);
          context.getIdMap().put(oldId, newId);
        }

        String composedId = composedObject.getId();
        String composedLid = composedObject.getLid();
        String composedIdNew = composedId;

        if (!util.isValidRegistryId(composedId)) { // Replace the id if it's not a valid ID already
          composedIdNew = util.createId();

          composedObject.setId(composedIdNew);

          // Add entry to idMap so old composedId and refs to it are mapped to composedIdNew
          context.getIdMap().put(composedId, composedIdNew);
        }

        if (composedLid == null || composedLid.trim().length() == 0) {
          composedObject.setLid(composedIdNew);
        }
        // Set the parent id of this composed object to point to the new parent
        bu.setParentIdForComposedObject(composedObject, idNew);
      }
    } catch (JAXRException e) {
      throw new RegistryException(e);
    } catch (JAXBException e) {
      throw new RegistryException(e);
    }
    return roNew;
  }