Exemplo n.º 1
0
  void doUpdateRecords(HttpServletRequest request, HttpServletResponse response, int serviceCall)
      throws ServletException, IOException, RecordServicesException {

    MetadataSchemaTypes schemaTypes = getSchemaTypes(COLLECTION);
    MetadataSchema schema = schemaTypes.getSchema("folder_default");
    int sizeInOctets = getRequiredIntegerParameter(request, SIZE_IN_OCTETS_PARAMETER);
    int qty = getRequiredIntegerParameter(request, QUANTITY_PARAMETER);
    RecordsFlushing recordsFlushing = getRecordsFlushing(request);

    List<Record> records = getRandomFolders(qty, serviceCall);
    for (int i = 0; i < records.size(); i++) {
      Record record = records.get(i);
      setRecordMetadatas(record, schema, Octets.octets(sizeInOctets), serviceCall + i);
    }
    Transaction transaction = new Transaction(records);
    transaction.setRecordFlushing(recordsFlushing);
    transaction.setOptimisticLockingResolution(OptimisticLockingResolution.EXCEPTION);
    getRecordServices().execute(transaction);
  }
  private Metadata givenReferenceToSchemaType(
      Metadata metadata, MetadataSchemaTypes types, String code, boolean childOf, String type) {
    when(metadata.getCode()).thenReturn(code);
    when(metadata.getLocalCode()).thenReturn(code.split("_")[2]);
    when(metadata.getType()).thenReturn(MetadataValueType.REFERENCE);

    AllowedReferences allowedReferences = new AllowedReferences(type, null);
    when(metadata.getAllowedReferences()).thenReturn(allowedReferences);
    when(types.getMetadata(code)).thenReturn(metadata);

    return metadata;
  }
  private MetadataSchemaType configureMockedSchemaTypeWithTaxonomyRelations(
      MetadataSchemaType type,
      MetadataSchemaTypes types,
      String code,
      Metadata... taxonomyRelations) {
    when(type.getCode()).thenReturn(code);
    List<Metadata> metadatas = Arrays.asList(taxonomyRelations);
    when(type.getAllReferencesToTaxonomySchemas(taxonomies)).thenReturn(metadatas);

    when(types.getSchemaType(code)).thenReturn(type);

    return type;
  }
  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;
  }
Exemplo n.º 5
0
  void doAddContent(HttpServletRequest request, HttpServletResponse response, int serviceCall)
      throws ServletException, IOException {

    IOServices ioServices = getIOServices();
    RecordsFlushing recordsFlushing = getRecordsFlushing(request);
    User user = getUserServices().getUserInCollection("admin", COLLECTION);

    List<Record> records = getRandomFolders(1, serviceCall);
    if (!records.isEmpty()) {

      ContentManager contentManager = getContentServices();
      MetadataSchemaTypes types = getSchemaTypes(COLLECTION);
      MetadataSchema documentSchema = types.getSchema(Document.DEFAULT_SCHEMA);
      Document document =
          new Document(getRecordServices().newRecordWithSchema(documentSchema), types);

      int qtyOfFiles = allPdfFiles.size();
      int index = setup.getRandom().nextInt(qtyOfFiles);
      File file = allPdfFiles.get(index);
      BufferedInputStream inputStream =
          new BufferedInputStream(ioServices.newFileInputStream(file, CONTENT_TO_ADD_STREAM));
      ContentVersionDataSummary dataSummary = getContentServices().upload(inputStream);
      document.setTitle(file.getName());
      document.setContent(contentManager.createMajor(user, file.getName(), dataSummary));
      document.setFolder(records.get(0).getId());

      Transaction transaction = new Transaction(asList(document.getWrappedRecord()));
      transaction.setRecordFlushing(recordsFlushing);
      transaction.setOptimisticLockingResolution(OptimisticLockingResolution.EXCEPTION);
      try {
        getRecordServices().execute(transaction);
      } catch (RecordServicesException e) {
        throw new RuntimeException(e);
      }

      IOUtils.closeQuietly(inputStream);
    }
  }
Exemplo n.º 6
0
  void doAddFolder(HttpServletRequest request, HttpServletResponse response, int serviceCall)
      throws ServletException, IOException, RecordServicesException {
    int addedFolder = addedFolderCounter.incrementAndGet();
    int qty = getRequiredIntegerParameter(request, QUANTITY_PARAMETER);
    int sizeInOctets = getRequiredIntegerParameter(request, SIZE_IN_OCTETS_PARAMETER);

    MetadataSchemaTypes schemaTypes = getSchemaTypes(COLLECTION);
    MetadataSchema folderSchema = schemaTypes.getSchema("folder_default");
    RecordsFlushing recordsFlushing = getRecordsFlushing(request);

    List<Record> records = new ArrayList<>();
    for (int i = 0; i < qty; i++) {
      int counter = addedFolder + i;

      String categoryId = level1And2CategoryIds.get(counter % level1And2CategoryIds.size());
      AdministrativeUnit administrativeUnit =
          new AdministrativeUnit(
              administrativeUnits.get(counter % administrativeUnits.size()), schemaTypes);

      Record newFolderRecord = getRecordServices().newRecordWithSchema(folderSchema);
      Folder newFolder = new Folder(newFolderRecord, schemaTypes);
      newFolder.setCategoryEntered(categoryId);
      newFolder.setRetentionRuleEntered(TEST_RULE_ID);
      newFolder.setCopyStatusEntered(CopyType.PRINCIPAL);
      newFolder.setOpenDate(new LocalDate(2010, 1, 1));
      newFolder.setFilingSpaceEntered(administrativeUnit.getFilingSpaces().get(0));
      newFolder.setAdministrativeUnitEntered(administrativeUnit);

      setRecordMetadatas(
          newFolderRecord, folderSchema, Octets.octets(sizeInOctets), addedFolder + i);
      records.add(newFolderRecord);
    }
    Transaction transaction = new Transaction(records);
    transaction.setRecordFlushing(recordsFlushing);
    getRecordServices().execute(transaction);
  }