List<Record> getRandomFolders(int qty, int counter) {
   MetadataSchema folderSchema =
       getMetadataSchemasManager().getSchemaTypes(COLLECTION).getSchema("folder_default");
   Metadata categoryMetadata = folderSchema.getMetadata(Folder.CATEGORY_ENTERED);
   SearchServices searchServices = getSearchServices();
   String categoryId = level1And2CategoryIds.get(counter % level1And2CategoryIds.size());
   LogicalSearchCondition condition =
       from(folderSchema).where(categoryMetadata).isEqualTo(categoryId);
   LogicalSearchQuery query = new LogicalSearchQuery(condition);
   query.setNumberOfRows(qty);
   return searchServices.search(query);
 }
  private MetadataSchema configureMockedSchemaWithTaxonomyRelations(
      MetadataSchema schema,
      MetadataSchemaTypes types,
      String code,
      Metadata... taxonomyRelations) {
    when(schema.getCode()).thenReturn(code);
    List<Metadata> metadatas = Arrays.asList(taxonomyRelations);
    when(schema.getTaxonomyRelationshipReferences(taxonomies)).thenReturn(metadatas);

    when(types.getSchema(code)).thenReturn(schema);

    return schema;
  }
 void doSearch(HttpServletRequest request, HttpServletResponse response, int serviceCall)
     throws ServletException, IOException {
   int qty = getRequiredIntegerParameter(request, QUANTITY_PARAMETER);
   MetadataSchema folderSchema =
       getMetadataSchemasManager().getSchemaTypes(COLLECTION).getSchema("folder_default");
   Metadata categoryMetadata = folderSchema.getMetadata("category");
   SearchServices searchServices = getSearchServices();
   String categoryId = level1And2CategoryIds.get(serviceCall % level1And2CategoryIds.size());
   LogicalSearchCondition condition =
       from(folderSchema).where(categoryMetadata).isEqualTo(categoryId);
   LogicalSearchQuery query = new LogicalSearchQuery(condition);
   query.setReturnedMetadatas(ReturnedMetadatasFilter.idVersionSchemaTitle());
   query.setNumberOfRows(qty);
   searchServices.search(query);
 }
  public void sort(MetadataVO[] propertyId, boolean[] ascending) {
    query.clearSort();

    for (int i = 0; i < propertyId.length; i++) {
      Metadata metadata;
      MetadataSchema schema = query.getSchemaCondition();
      MetadataVO metadataVO = propertyId[i];
      metadata = schema.getMetadata(metadataVO.getCode());

      if (ascending[i]) {
        query = query.sortAsc(metadata);
      } else {
        query = query.sortDesc(metadata);
      }
    }
  }
 private void addCopyRetentionRuleError(
     String code, MetadataSchema schema, ValidationErrors validationErrors) {
   Map<String, String> parameters = new HashMap<>();
   parameters.put(RecordMetadataValidator.METADATA_CODE, RetentionRule.COPY_RETENTION_RULES);
   parameters.put(
       RecordMetadataValidator.METADATA_LABEL,
       schema.getMetadata(RetentionRule.COPY_RETENTION_RULES).getLabel());
   validationErrors.add(getClass(), code, parameters);
 }
  private void setRecordMetadatas(
      Record record, MetadataSchema schema, Octets octets, int counter) {
    Metadata description = schema.getMetadata("description");

    RandomWordsIterator wordsIterator = setup.getRandomWordsIterator(counter);

    record.set(Schemas.TITLE, wordsIterator.nextWords(8));
    record.set(description, wordsIterator.nextWordsOfLength(octets));
  }
 private void addCopyRetentionRuleIntegrityError(
     int index, String field, MetadataSchema schema, ValidationErrors validationErrors) {
   Map<String, String> parameters = new HashMap<>();
   parameters.put(COPY_RETENTION_RULE_FIELD_REQUIRED_FIELD, field);
   parameters.put(COPY_RETENTION_RULE_FIELD_REQUIRED_INDEX, "" + index);
   parameters.put(RecordMetadataValidator.METADATA_CODE, RetentionRule.COPY_RETENTION_RULES);
   parameters.put(
       RecordMetadataValidator.METADATA_LABEL,
       schema.getMetadata(RetentionRule.COPY_RETENTION_RULES).getLabel());
   validationErrors.add(getClass(), COPY_RETENTION_RULE_FIELD_REQUIRED, parameters);
 }
 private void setCategoriesAndClassificationIdsList() {
   SearchServices searchServices = getSearchServices();
   MetadataSchema categorySchema =
       getMetadataSchemasManager().getSchemaTypes(COLLECTION).getSchema(Category.DEFAULT_SCHEMA);
   MetadataSchema administrativeUnitSchema =
       getMetadataSchemasManager()
           .getSchemaTypes(COLLECTION)
           .getSchema(AdministrativeUnit.DEFAULT_SCHEMA);
   Metadata filingSpaceMetadata =
       administrativeUnitSchema.getMetadata(AdministrativeUnit.FILING_SPACES);
   Metadata parentCategoryMetadata = categorySchema.getMetadata("parent");
   level1And2CategoryIds =
       searchServices.searchRecordIds(
           new LogicalSearchQuery(
               LogicalSearchQueryOperators.from(categorySchema)
                   .where(parentCategoryMetadata)
                   .isNotNull()));
   administrativeUnits =
       searchServices.search(
           new LogicalSearchQuery(
               LogicalSearchQueryOperators.from(administrativeUnitSchema)
                   .where(filingSpaceMetadata)
                   .isNotNull()));
 }