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; }
@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"); }
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); }
private void replaceResourceInfoToMetadataRecord(String fileName, long fileSize) { spiderRecordRead.removeChild(RESOURCE_INFO); addResourceInfoToMetadataRecord(fileName, fileSize); }
private boolean recordHasNoResourceInfo() { return !spiderRecordRead.containsChildWithNameInData(RESOURCE_INFO); }
private String extractDataDividerFromData(SpiderDataGroup spiderDataGroup) { SpiderDataGroup recordInfo = spiderDataGroup.extractGroup(RECORD_INFO); SpiderDataGroup dataDivider = recordInfo.extractGroup("dataDivider"); return dataDivider.extractAtomicValue("linkedRecordId"); }