@Override
 public List<Shipment> getShipments() {
   List<Shipment> res = new ArrayList<Shipment>();
   for (Shipment s : shipments.find()) {
     res.add(s);
   }
   return res;
 }
 protected void loadCache() {
   DBCursor<MongoCodeLookup> lookupCurs = lookupColl_target.find();
   lookupCurs.addOption(com.mongodb.Bytes.QUERYOPTION_NOTIMEOUT);
   while (lookupCurs.hasNext()) {
     MongoCodeLookup lookup = lookupCurs.next();
     addInCache(lookup);
   }
 }
 public boolean updateGameLog(String pbfId, String oldUsername, String newUsername) {
   List<GameLog> gameLogs =
       gameLogCollection.find(DBQuery.is("pbfId", pbfId).is("username", oldUsername)).toArray();
   for (GameLog gl : gameLogs) {
     gl.setUsername(newUsername);
     gameLogCollection.updateById(gl.getId(), gl);
   }
   return !gameLogs.isEmpty();
 }
 @Override
 public List<Spoke> getSpokes() {
   JacksonDBCollection<Spoke, String> col =
       JacksonDBCollection.wrap(mongoDB.getCollection("spokes"), Spoke.class, String.class);
   List<Spoke> res = new ArrayList<Spoke>();
   for (Spoke s : col.find()) {
     res.add(s);
   }
   return res;
 }
 @Override
 public List<Hub> getHubs() {
   JacksonDBCollection<Hub, String> col =
       JacksonDBCollection.wrap(mongoDB.getCollection("hubs"), Hub.class, String.class);
   List<Hub> res = new ArrayList<Hub>();
   for (Hub s : col.find()) {
     res.add(s);
   }
   return res;
 }
 @Override
 public List<TruckType> getTruckTypes() {
   JacksonDBCollection<TruckType, String> col =
       JacksonDBCollection.wrap(
           mongoDB.getCollection("truckTypes"), TruckType.class, String.class);
   List<TruckType> res = new ArrayList<TruckType>();
   for (TruckType s : col.find()) {
     res.add(s);
   }
   return res;
 }
  private <T extends AbstractEdmEntityImpl, G extends MongoTermList<T>> boolean migratePhaseTwo(
      JacksonDBCollection<MongoTerm, String> termColl_source,
      JacksonDBCollection<MongoTerm, String> termColl_target,
      ContextualCategory contextualCategory,
      int skip)
      throws UnknownHostException {
    int counter = 0;
    int interval = 0;
    while (true) {
      try {

        DBCursor<MongoTerm> termCurs = termColl_source.find().skip(skip);
        termCurs.addOption(com.mongodb.Bytes.QUERYOPTION_NOTIMEOUT);
        while (termCurs.hasNext()) {
          MongoTerm term = termCurs.next();
          counter++;
          interval++;
          if (interval == 1000) {
            System.out.println(
                String.format("Phase 2 (%s): %d ", contextualCategory.getEntityClass(), counter));
            interval = 0;
          }

          term.setId(null);
          String codeUri = lookupOriginalCodeUri(term.getCodeUri());

          if (codeUri != null) {
            term.setCodeUri(codeUri);
            try {
              termColl_target.insert(term);

            } catch (DuplicateKeyException me) {
              // do nothing
              // System.out.println("Duplicate:" +
              // term.toString());
              continue;
            }
          }
        }
        termCurs.close();
        break;
      } catch (Exception e) {
        e.printStackTrace();
        initialiseConnections();
        counter--;
        skip = counter;
        continue;
      }
    }
    return true;
  }
  private <T extends AbstractEdmEntityImpl, G extends MongoTermList<T>> boolean migratePhaseOne(
      JacksonDBCollection<G, String> termListColl_source,
      JacksonDBCollection<MongoTerm, String> termColl_source,
      JacksonDBCollection<G, String> termListColl_target,
      JacksonDBCollection<MongoTerm, String> termColl_target,
      ContextualCategory contextualCategory,
      String termCollection)
      throws UnknownHostException {
    int skip = 0;
    int counter = 0;
    while (true) {
      try {
        DBCursor<G> curs =
            termListColl_source
                .find(new BasicDBObject("entityType", contextualCategory.getEntityClass()))
                .skip(skip);
        curs.addOption(com.mongodb.Bytes.QUERYOPTION_NOTIMEOUT);

        while (curs.hasNext()) {
          long nextSequence = nextSequence(contextualCategory);
          counter++;

          G termList = curs.next();
          String newCodeUri =
              String.format(
                  "http://data.europeana.eu/%s/base" + "/%d",
                  contextualCategory.getLabel(), nextSequence);
          String oldCodeUri = termList.getCodeUri();

          MongoCodeLookup lookup = new MongoCodeLookup();
          lookup.setCodeUri(newCodeUri);
          lookup.setOriginalCodeUri(oldCodeUri);
          lookupColl_target.insert(lookup);

          lookupCodeUri.put(newCodeUri, oldCodeUri);
          lookupOriginalCodeUri.put(oldCodeUri, newCodeUri);
        }
        curs.close();
        break;
      } catch (Exception e) {
        e.printStackTrace();
        initialiseConnections();

        skip = counter - 1;
        continue;
      }
    }
    return true;
  }
  public ConceptTermList findOneHavingTerms() {
    DBCursor<ConceptTermList> curs =
        conceptTermListColl_source.find(
            new BasicDBObject("entityType", ContextualCategory.CONCEPT.getEntityClass()));
    curs.addOption(com.mongodb.Bytes.QUERYOPTION_NOTIMEOUT);
    ConceptTermList conceptTermList = null;
    while (curs.hasNext()) {

      ConceptTermList termList = curs.next();
      if (termList.getTerms() != null && !termList.getTerms().isEmpty()) {
        conceptTermList = termList;
        break;
      }
    }
    curs.close();
    return conceptTermList;
  }
  @GET
  public List<MongoDocument> fetch(@PathParam("collection") String collection) {
    final JacksonDBCollection<MongoDocument, String> coll =
        JacksonDBCollection.wrap(
            mongoDB.getCollection(collection), MongoDocument.class, String.class);
    final DBCursor<MongoDocument> cursor = coll.find();
    final List<MongoDocument> l = new ArrayList<>();

    try {
      while (cursor.hasNext()) {
        l.add(cursor.next());
      }
    } finally {
      cursor.close();
    }

    return l;
  }
Example #11
0
  public List<Account> find(DBQuery.Query query) {

    return repository.find(query).toArray();
  }
 @Override
 public Set<Output> loadAll() {
   return toAbstractSetType(coll.find().toArray());
 }
  private <
          T extends AbstractEdmEntityImpl,
          G extends MongoTermList<T>,
          H extends AbstractRepresentationMigration<T>>
      boolean migratePhaseThree(
          JacksonDBCollection<G, String> termListColl_source,
          JacksonDBCollection<G, String> termListColl_target,
          H representationMagrition,
          ContextualCategory contextualCategory,
          int skip)
          throws UnknownHostException {
    int counter = 0;
    int interval = 0;
    while (true) {
      try {

        DBCursor<G> curs =
            termListColl_source
                .find(new BasicDBObject("entityType", contextualCategory.getEntityClass()))
                .skip(skip);
        curs.addOption(com.mongodb.Bytes.QUERYOPTION_NOTIMEOUT);

        while (curs.hasNext()) {
          G termList = curs.next();
          counter++;
          interval++;
          if (interval == 1000) {
            System.out.println(
                String.format("Phase 3 (%s): %d ", contextualCategory.getEntityClass(), counter));
            interval = 0;
          }

          String originalUri = termList.getCodeUri();
          String codeUri = lookupOriginalCodeUri(termList.getCodeUri());
          termList.setCodeUri(codeUri);
          termList.setId(null);

          String parent = termList.getParent();

          if (StringUtils.isNotBlank(parent)) {

            String parentCodeUri = lookupOriginalCodeUri(parent);
            if (parentCodeUri == null) {
              termList.setParent(null);
            } else {
              termList.setParent(parentCodeUri);
            }
          }

          T representation = termList.getRepresentation();
          representationMagrition.migrateRepresentation(codeUri, originalUri, representation);
          termList.setOwlSameAs(((PlaceImpl) representation).getOwlSameAs());
          try {
            termListColl_target.insert(termList);

          } catch (DuplicateKeyException me) {
            continue;
          }
        }
        curs.close();
        break;
      } catch (Exception e) {
        e.printStackTrace();
        initialiseConnections();
        counter--;
        skip = counter;
        continue;
      }
    }
    return true;
  }
 public List<GameLog> getGameLogsBelongingToPlayer(String pbfId, String username) {
   return gameLogCollection.find(DBQuery.is("pbfId", pbfId).is("username", username)).toArray();
 }
 public List<GameLog> getGameLogs(String pbfId) {
   return gameLogCollection.find(DBQuery.is("pbfId", pbfId)).toArray();
 }