private SpiderDataGroup createRecordInfo() {
   SpiderDataGroup recordInfo = SpiderDataGroup.withNameInData("recordInfo");
   recordInfo.addChild(SpiderDataAtomic.withNameInDataAndValue("id", "place:0001"));
   recordInfo.addChild(SpiderDataAtomic.withNameInDataAndValue("type", "place"));
   recordInfo.addChild(SpiderDataAtomic.withNameInDataAndValue("createdBy", "userId"));
   return recordInfo;
 }
Example #2
0
  @Override
  public SpiderDataRecord upload(
      String authToken, String type, String id, InputStream stream, String fileName) {
    this.authToken = authToken;
    this.recordType = type;
    tryToGetActiveUser();
    checkUserIsAuthorizedForActionOnRecordType();

    checkRecordTypeIsChildOfBinary();

    DataGroup recordRead = recordStorage.read(type, id);
    spiderRecordRead = SpiderDataGroup.fromDataGroup(recordRead);
    checkUserIsAuthorisedToUploadData(recordRead);
    checkStreamIsPresent(stream);
    checkFileNameIsPresent(fileName);
    streamId = idGenerator.getIdForType(type + "Binary");

    String dataDivider = extractDataDividerFromData(spiderRecordRead);
    long fileSize = streamStorage.store(streamId, dataDivider, stream);

    addOrReplaceResourceInfoToMetdataRecord(fileName, fileSize);

    SpiderRecordUpdater spiderRecordUpdater = SpiderInstanceProvider.getSpiderRecordUpdater();
    return spiderRecordUpdater.updateRecord(userId, type, id, spiderRecordRead);
  }
  @Test
  public void testToRestWithGroup() {
    SpiderDataGroup spiderDataGroup = SpiderDataGroup.withNameInData("groupId");
    spiderDataGroup.addChild(createRecordInfo());
    SpiderDataList spiderDataList = SpiderDataList.withContainDataOfType("place");
    spiderDataList.addData(spiderDataGroup);
    spiderDataList.setTotalNo("10");
    spiderDataList.setFromNo("0");
    spiderDataList.setToNo("1");

    DataListSpiderToRestConverter converter =
        DataListSpiderToRestConverter.fromSpiderDataListWithBaseURL(spiderDataList, baseURL);

    RestDataList recordList = converter.toRest();

    RestDataGroup restDataGroup = ((RestDataGroup) recordList.getDataList().get(0));

    assertEquals(restDataGroup.getNameInData(), "groupId");
  }
Example #4
0
  private void addResourceInfoToMetadataRecord(String fileName, long fileSize) {
    SpiderDataGroup resourceInfo = SpiderDataGroup.withNameInData(RESOURCE_INFO);
    spiderRecordRead.addChild(resourceInfo);

    SpiderDataGroup master = SpiderDataGroup.withNameInData("master");
    resourceInfo.addChild(master);

    SpiderDataAtomic streamId2 = SpiderDataAtomic.withNameInDataAndValue("streamId", streamId);
    master.addChild(streamId2);

    SpiderDataAtomic uploadedFileName =
        SpiderDataAtomic.withNameInDataAndValue("filename", fileName);
    master.addChild(uploadedFileName);

    SpiderDataAtomic size =
        SpiderDataAtomic.withNameInDataAndValue("filesize", String.valueOf(fileSize));
    master.addChild(size);

    SpiderDataAtomic mimeType =
        SpiderDataAtomic.withNameInDataAndValue("mimeType", "application/octet-stream");
    master.addChild(mimeType);
  }
Example #5
0
 private void replaceResourceInfoToMetadataRecord(String fileName, long fileSize) {
   spiderRecordRead.removeChild(RESOURCE_INFO);
   addResourceInfoToMetadataRecord(fileName, fileSize);
 }
Example #6
0
 private boolean recordHasNoResourceInfo() {
   return !spiderRecordRead.containsChildWithNameInData(RESOURCE_INFO);
 }
Example #7
0
 private String extractDataDividerFromData(SpiderDataGroup spiderDataGroup) {
   SpiderDataGroup recordInfo = spiderDataGroup.extractGroup(RECORD_INFO);
   SpiderDataGroup dataDivider = recordInfo.extractGroup("dataDivider");
   return dataDivider.extractAtomicValue("linkedRecordId");
 }