Package com.esri.gpt.framework.collection

Examples of com.esri.gpt.framework.collection.StringSet


    if (meaning instanceof PropertyMeaning.AnyText) {
      PropertyMeaning.AnyText anyText = (PropertyMeaning.AnyText)meaning;
      storable = new AnyTextProperty(fieldName,anyText.getNamesToConsider());

    } else if (comparisonType.equals(PropertyComparisonType.ANYTEXT)) {
      storable = new AnyTextProperty(fieldName,new StringSet());
     
    } else if (fieldName.equalsIgnoreCase("body")) {
      storable = new Storeable(fieldName);
      DatastoreField field = new DatastoreField(fieldName,
          Field.Store.NO,Field.Index.ANALYZED,Field.TermVector.NO);
View Full Code Here


     
      Term termUuid = new Term(fldUuid);
      if (bCheckIndex) {
        termDocs = this.reader.termDocs();
      }
      StringSet delUuids = new StringSet();
     
      // build the database query
      StringBuffer sb = new StringBuffer("SELECT");
      sb.append(" ").append(this.resourceTable).append(".DOCUUID");
      sb.append(",").append(this.resourceTable).append(".APPROVALSTATUS");
      sb.append(",").append(this.resourceTable).append(".PROTOCOL_TYPE");
      sb.append(",").append(this.resourceTable).append(".FINDABLE");
      sb.append(",").append(this.resourceTable).append(".UPDATEDATE");
      sb.append(",").append(this.resourceTable).append(".ACL");
      sb.append(" FROM ").append(this.resourceTable);
      String sql = sb.toString();
      LOGGER.finest(sql);
     
      // execute the query, walk through the database records
      Connection con = this.context.getConnectionBroker().returnConnection("").getJdbcConnection();
      st = con.prepareStatement(sql);
      ResultSet rs = st.executeQuery();
      if (this.checkInterrupted()) return;
      if (useCollections && hasCollections) {
        stCol = con.prepareStatement(sqlCol);
      }
     
      while (rs.next()) {
       
        info.numProcessed++;
        info.loopCount++;
        long nDbTimeModified = 0;
        Timestamp tsDbModified = null;
        String sDbAcl = null;
        boolean bIndexable = false;
       
        // read the database uuid and approval status
        String uuid = rs.getString(1);
        String status = rs.getString(2);
        String protocolType = Val.chkStr(rs.getString(3));
        boolean findable = Val.chkBool(rs.getString(4),false);

        bIndexable = (status != null) &&
                     (status.equalsIgnoreCase("approved") || status.equalsIgnoreCase("reviewed"));
        if (bIndexable && protocolType.length()>0 && !findable) {
          bIndexable = false;
        }
       
        // read the database modification date
        if (bIndexable) {
          tsDbModified = rs.getTimestamp(5);
          if (tsDbModified != null) {
            nDbTimeModified = tsDbModified.getTime();
          }
          bIndexable = (nDbTimeModified > 0);
        }
       
        // for non-indexable documents, delete
        if (!bIndexable) {
          info.numNonIndexable++;
          if (bCheckIndex) {
            termDocs.seek(termUuid.createTerm(uuid));
            if (termDocs.next()) {
              info.numNonIndexableFound++;
              info.numRequiringDelete++;
              delUuids.add(uuid);
              if (delUuids.size() >= this.maxDeleteTokens) {
                if (this.checkInterrupted()) return;
                this.deleteDocuments(delUuids);
                info.numDocsDeleted += delUuids.size();
                delUuids.clear();
                if (this.checkInterrupted()) return;
              }
            }  
          }
        }
       
        // for indexable documents, check to ensure that they are in sync
        if (bIndexable) {
          info.numIndexable++;
          boolean bRequiresUpdate = true;
         
          // find the document within the index
          if (bCheckIndex) {
            termDocs.seek(termUuid.createTerm(uuid));
            if (termDocs.next()) {
              info.numIndexableFound++;
              Document doc = this.reader.document(termDocs.doc(),selector);
              if (doc != null) {
                bRequiresUpdate = false;
               
                // check the modification date
                long nIdxTimeModified = 0;
                String sModified = doc.get(fldModified);
                if (sModified != null) {
                  try {
                    nIdxTimeModified = Long.valueOf(sModified);
                  } catch (NumberFormatException e) {
                    nIdxTimeModified = 0;
                  }
                }
                bRequiresUpdate = (nIdxTimeModified == 0) || (nDbTimeModified > nIdxTimeModified);
                if (bRequiresUpdate) info.numWithInconsistentDates++;
                 
                // check the acl
                if (!bRequiresUpdate && bCheckAcl) {
                  long tAclStartMillis = System.currentTimeMillis();
                  bRequiresUpdate = true;
                  String[] aclsDb = null;
                  sDbAcl = rs.getString(6);
                  try {
                    // use an internal method for quick parsing
                    //aclsDb = acl.makeDocumentAcl(sDbAcl);
                    aclsDb = this.parseAcl(sDbAcl);
                  } catch (Exception eacl) {
                    String sMsg = "Error parsing acl";
                    sMsg += ", uuid="+uuid+"\n"+Val.chkStr(eacl.getMessage());
                    LOGGER.log(Level.WARNING,sMsg,eacl);
                  }               
                                   
                  if (aclsDb == null) aclsDb = new String[0];
                  ArrayList<String> aclsIdx = new ArrayList<String>();
                  Field[] aclFields = doc.getFields(fldAcl);
                  if ((aclFields != null) && (aclFields.length > 0)) {
                    for (Field aclField: aclFields) {
                      aclsIdx.add(aclField.stringValue());
                    }
                  }
                  if (aclsDb.length == aclsIdx.size()) {
                    int nMatched = 0;
                    if (aclsDb.length > 0) {
                      for (String s1: aclsDb) {
                        for (String s2: aclsIdx) {
                          if (s1.equalsIgnoreCase(s2)) {
                            nMatched++;
                            break;
                          }
                        }
                      }
                    }
                    bRequiresUpdate = (nMatched != aclsDb.length);
                  }
                  if (bRequiresUpdate) info.numWithInconsistentAcls++;
                  info.aclMillis += (System.currentTimeMillis() - tAclStartMillis);
                }
               
                // check collection membership
                if (!bRequiresUpdate && useCollections) {
                  long tColStartMillis = System.currentTimeMillis();
                  bRequiresUpdate = true;
                 
                  ArrayList<String> colDb = new ArrayList<String>();
                  if (useCollections && hasCollections) {
                    stCol.clearParameters();
                    stCol.setString(1,uuid);
                    ResultSet rsCol = stCol.executeQuery();
                    while (rsCol.next()) {
                      String sCUuid = rsCol.getString(1);
                      for (String[] col: collections) {
                        if (sCUuid.equals(col[0])) { 
                          colDb.add(col[1]);
                          break;
                        }
                      }
                    }
                    rsCol.close();
                  }
                 
                  ArrayList<String> colIdx = new ArrayList<String>();
                  Field[] colFields = doc.getFields("isPartOf");
                  if ((colFields != null) && (colFields.length > 0)) {
                    for (Field colField: colFields) {
                      colIdx.add(colField.stringValue());
                    }
                  }
                  if (colDb.size() == colIdx.size()) {
                    int nMatched = 0;
                    if (colDb.size() > 0) {
                      for (String s1: colDb) {
                        for (String s2: colIdx) {
                          if (s1.equalsIgnoreCase(s2)) {
                            nMatched++;
                            break;
                          }
                        }
                      }
                    }
                    bRequiresUpdate = (nMatched != colDb.size());
                  }
                  if (bRequiresUpdate) info.numWithInconsistentColMembership++;
                  info.colMillis += (System.currentTimeMillis() - tColStartMillis);
                 }
               
              }
            }
          }
         
          // execute the update if required
          if (bRequiresUpdate) {
            if (this.checkInterrupted()) return;       
            try {
              if (bCheckAcl) {
                if (sDbAcl == null) sDbAcl = rs.getString(6);
              }
              String sXml = Val.chkStr(this.readXml(uuid));
              if (sXml.length() > 0) {
                info.numRequiringUpdate++;
                MetadataDocument mdDoc = new MetadataDocument();
                Schema schema = mdDoc.prepareForView(this.context,sXml);
                this.adapter.publishDocument(uuid,tsDbModified,schema,sDbAcl);
                info.numDocsUpdated++;
              }
            } catch (SchemaException se) {
             
              // dont' allow the entire process to fail over one bad xml
              String sMsg = "Error indexing document during synchronization";
              sMsg += ", uuid="+uuid+"\n"+Val.chkStr(se.getMessage());
              LOGGER.log(Level.WARNING,sMsg,se);
            }
            if (this.checkInterrupted()) return;
          }
         
        }
        // cache the synchronized uuids
        if (this.synchedUuidCache != null) {
          this.synchedUuidCache.put(uuid,"");
          if (this.synchedUuidCache.size() > this.maxUuidCache) {
            this.synchedUuidCache = null;
          }
        }
       
        // log a status message if the feedback threshold was reached
        if (this.checkInterrupted()) return;
        if ((System.currentTimeMillis() - info.loopStartMillis) >= this.feedbackMillis) {
          LOGGER.info(info.getLoopMessage());
        }
      
      }
     
      // delete any documents left over in the buffer
      if (delUuids.size() >= 0) {
        if (this.checkInterrupted()) return;
        this.deleteDocuments(delUuids);
        info.numDocsDeleted += delUuids.size();
      }
     
      LOGGER.info(info.getStepMessage());
    } finally {
      try {if (st != null) st.close();} catch (Exception ef) {}
View Full Code Here

  private void walkIndex(WalkIndexInfo info)
    throws IOException, SQLException, CatalogIndexException {
    LOGGER.fine("Checking indexed documents...");
    TermEnum termEnum = null;
    try {
      StringSet chkUuids = new StringSet();
      StringSet delUuids = new StringSet();
      String fldUuid = Storeables.FIELD_UUID;
      termEnum = this.reader.terms(new Term(fldUuid));
      do {
        Term term = termEnum.term();
        if ((term == null) || !term.field().equals(fldUuid)) {
          break;
        }
        info.numProcessed++;
        info.loopCount++;
        
        // check the cache to see if the uuid was already synchronized,
        // otherwise add it to the set of uuids to check
        String uuid = term.text();
        if (this.synchedUuidCache != null) {
          if (this.synchedUuidCache.containsKey(uuid)) {
            info.numFoundInCache++;
          } else {
            chkUuids.add(uuid);
          }
        } else {
          chkUuids.add(uuid);
        }
       
        // check to ensure that these documents are indexable
        if (chkUuids.size() >= this.maxSqlTokens) {
          if (this.checkInterrupted()) return;
          this.ensureIndexable(info,chkUuids,delUuids);
          chkUuids.clear();
          if (this.checkInterrupted()) return;
          if ((System.currentTimeMillis() - info.loopStartMillis) >= this.feedbackMillis) {
            LOGGER.info(info.getLoopMessage());
          }
        }
       
        // log a status message if the loop threshold was reached
        if (info.loopCount >= info.loopThreshold) {
          if (this.checkInterrupted()) return;
          if ((System.currentTimeMillis() - info.loopStartMillis) >= this.feedbackMillis) {
            LOGGER.info(info.getLoopMessage());
          }
        }
       
     } while (termEnum.next());
     
      // check any documents left over in the buffers
      if (chkUuids.size() > 0) {
        if (this.checkInterrupted()) return;
        this.ensureIndexable(info,chkUuids,delUuids);
        if (this.checkInterrupted()) return;
      }
      if (delUuids.size() >= 0) {
        if (this.checkInterrupted()) return;
        this.deleteDocuments(delUuids);
        info.numDocsDeleted += delUuids.size();
        if (this.checkInterrupted()) return;
      }
     
      LOGGER.info(info.getStepMessage());
    } finally {
View Full Code Here

* @throws Exception if an exception occurs
*/
public void execute() throws Exception {
  int nRows = 0;
  String sAction = getActionCriteria().getActionKey();
  StringSet uuids = getActionCriteria().getSelectedRecordIdSet();
  ImsMetadataAdminDao adminDao = new ImsMetadataAdminDao(getRequestContext());

  // check for approval status updates
  if (sAction.equalsIgnoreCase("setPosted")) {
    nRows = adminDao.updateApprovalStatus(getPublisher(),uuids,MmdEnums.ApprovalStatus.posted);
View Full Code Here

      }
     
      ImsMetadataAdminDao dao = new ImsMetadataAdminDao(context);
      String resourceTable =  context.getCatalogConfiguration().getResourceTableName();
      String resourceDataTable = context.getCatalogConfiguration().getResourceDataTableName();
      StringSet delUuids = new StringSet();
      MetadataAcl acl = new MetadataAcl(context);
      boolean bCheckAcl = !acl.isPolicyUnrestricted();
     
      StringBuilder sbIds = new StringBuilder();
      for (String sUuid: ids) {
        if (sbIds.length() > 0) sbIds.append(",");
        sbIds.append("'").append(sUuid).append("'");
      }
     
      StringBuilder sb = new StringBuilder("SELECT");
      sb.append(" ").append(resourceTable).append(".DOCUUID");
      sb.append(",").append(resourceTable).append(".APPROVALSTATUS");
      sb.append(",").append(resourceTable).append(".PROTOCOL_TYPE");
      sb.append(",").append(resourceTable).append(".FINDABLE");
      sb.append(",").append(resourceTable).append(".UPDATEDATE");
      sb.append(",").append(resourceTable).append(".ACL");
      sb.append(" FROM ").append(resourceTable);
      sb.append(" WHERE DOCUUID IN (").append(sbIds.toString()).append(")");
      String sql = sb.toString();
      LOGGER.finest(sql);
     
      ManagedConnection mc = context.getConnectionBroker().returnConnection("");
      Connection con = mc.getJdbcConnection();
      IClobMutator mutator = mc.getClobMutator();
     
      st = con.prepareStatement(sql);
      ResultSet rs = st.executeQuery();
      if (Thread.interrupted()) return;
      while (rs.next()) {
        if (Thread.interrupted()) return;
       
        String uuid = rs.getString(1);
        String status = rs.getString(2);
        String protocolType = Val.chkStr(rs.getString(3));
        boolean findable = Val.chkBool(rs.getString(4),false);

        boolean bIndexable = (status != null) &&
          (status.equalsIgnoreCase("approved") || status.equalsIgnoreCase("reviewed"));
        if (bIndexable && protocolType.length()>0 && !findable) {
          bIndexable = false;
        }
       
        if (!bIndexable) {
          delUuids.add(uuid);
        } else {         
          Timestamp tsDbModified = rs.getTimestamp(5);
          String sDbAcl = null;
          if (bCheckAcl) {
            sDbAcl = rs.getString(6);
          }
         
          try {
            String sXml = Val.chkStr(dao.readXml(uuid));
            if (sXml.length() > 0) {
              MetadataDocument mdDoc = new MetadataDocument();
              Schema schema = mdDoc.prepareForView(context,sXml);
              adapter.publishDocument(uuid,tsDbModified,schema,sDbAcl);
            }
          } catch (SchemaException se) {
           
            // don't allow the entire process to fail over one bad xml
            String sMsg = "Error indexing document during the handling of a remote request";
            sMsg += ", uuid="+uuid+"\n"+Val.chkStr(se.getMessage());
            LOGGER.log(Level.WARNING,sMsg,se);
          }
        }
      }
     
      if (Thread.interrupted()) return;
      if (delUuids.size() > 0) {
        adapter.deleteDocuments(ids);
      }
    } finally {
      try {if (st != null) st.close();} catch (Exception ef) {}
      try {
View Full Code Here

      continue;
    }
   
    // map rids to canonical engine
    String engineCanonicalName = engine.getClass().getCanonicalName();
    StringSet ridEngineSet =
      mapEngineName2rids.get(engineCanonicalName);
    if(ridEngineSet == null) {
      ridEngineSet = new StringSet();
      mapEngineName2rids.put(engineCanonicalName, ridEngineSet)
    }
    ridEngineSet.add(rid);
   
    // save engine
    if(!mapEngineName2Engine.containsKey(engineCanonicalName)) {
      mapEngineName2Engine.put(engineCanonicalName, engine);
    }
  }
 
  // create instances of search engines using asearchegine.createinstances
  Set<String> setEngineName = mapEngineName2rids.keySet();
  for(String sEngineName: setEngineName) {
    StringSet setEngineRids = mapEngineName2rids.get(sEngineName);
    ASearchEngine searchEngine = mapEngineName2Engine.get(sEngineName);
    try {
      searchEngine.setRequestContext(context);
      searchEngine.setMessageBroker(messageBroker);
      Map<String, Object> searchEngineInstances =
View Full Code Here

    CswNamespaces ns = new CswNamespaces();
    XPath xpath = XPathFactory.newInstance().newXPath();
    xpath.setNamespaceContext(ns.makeNamespaceContext());
   
    // if specific type names were requested, then remove those that were not requested
    StringSet typeNames = drOptions.getTypeNames();
    if ((typeNames != null) && (typeNames.size() > 0)) {
      String expr = "/csw:DescribeRecordResponse/csw:SchemaComponent/xsd:schema";
      NodeList nlSchemas = (NodeList)xpath.evaluate(expr,dom,XPathConstants.NODESET);
      if ((nlSchemas != null) && (nlSchemas.getLength() > 0)) {
        ArrayList<Node> remove = new ArrayList<Node>();
        ArrayList<Node> removeParent = new ArrayList<Node>();
        for (int i=0; i<nlSchemas.getLength(); i++) {
          Node ndSchema = nlSchemas.item(i);
          String typeName = Val.chkStr(xpath.evaluate("@id",ndSchema));
          if ((typeName.length() > 0) && !typeNames.contains(typeName)) {
            remove.add(ndSchema);
          }
        }
       
        for (Node node: remove) {
View Full Code Here

   * @param startIndex the index to begin reading
   * @return the set of UUIDs
   * @throws CatalogIndexException if an exception occurs
   */
  private StringSet readUuids(int startIndex, int maxUuids) throws CatalogIndexException {
    StringSet ssUuids = new StringSet();
    IndexSearcher searcher = null;
    TermEnum terms = null;
    try {
      String sField = Storeables.FIELD_UUID;
      searcher = newSearcher();
      terms = searcher.getIndexReader().terms(new Term(sField,""));
      int nCount = 0;
      while (sField.equals(terms.term().field())) {       
        if(nCount >= startIndex){
         ssUuids.add(terms.term().text());
        }
        nCount++;
        if (nCount >= (startIndex + maxUuids)) break;
        if (!terms.next()) break;
      }
View Full Code Here

   */
  public StringSet validateValues(String locator,
                                  String[] parsed,
                                  boolean required)
    throws OwsException {
    StringSet requested = new StringSet();
    if (parsed == null) {
      if (required) {
        String msg = "The parameter value was missing.";
        throw new OwsException(OwsException.OWSCODE_MissingParameterValue,locator,msg);
      }
    } else if (parsed.length == 0) {
      String msg = "The parameter value was empty.";
      throw new OwsException(OwsException.OWSCODE_InvalidParameterValue,locator,msg);
    } else {
      int count = 0;
      for (String value: parsed) {
        value = Val.chkStr(value);
        if (value.length() == 0) {
          String msg = "The parameter value was empty.";
          throw new OwsException(OwsException.OWSCODE_InvalidParameterValue,locator,msg);
        } else {
          requested.add(value);
          count++;
        }
      }
      if (required && (count == 0)) {
        String msg = "No valid values were supplied.";
View Full Code Here

  public StringSet validateValues(ISupportedValues supported,
                                  String locator,
                                  String[] parsed,
                                  boolean required)
    throws OwsException {
    StringSet requested = new StringSet();
    if (parsed == null) {
      if (required) {
        String msg = "The parameter value was missing.";
        throw new OwsException(OwsException.OWSCODE_MissingParameterValue,locator,msg);
      }
    } else if (parsed.length == 0) {
      String msg = "The parameter value was empty.";
      throw new OwsException(OwsException.OWSCODE_InvalidParameterValue,locator,msg);
    } else {
      for (String value: parsed) {
        value = Val.chkStr(value);
        if (value.length() == 0) {
          String msg = "The parameter value was empty.";
          throw new OwsException(OwsException.OWSCODE_InvalidParameterValue,locator,msg);
        } else if (supported == null) {
          String msg = "This parameter value is not supported: "+value;
          throw new OwsException(OwsException.OWSCODE_InvalidParameterValue,locator,msg);
        } else {
          String validValue = supported.getSupportedValue(value);
          if (validValue == null) {
            String msg = "This parameter value is not supported: "+value;
            throw new OwsException(OwsException.OWSCODE_InvalidParameterValue,locator,msg);
          } else {
            requested.add(validValue);
          }
        }
      }
    }
    return requested;
View Full Code Here

TOP

Related Classes of com.esri.gpt.framework.collection.StringSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.