FileEntryMetadataOpenGraphTagsProvider { public Iterable<KeyValuePair> getFileEntryMetadataOpenGraphTagKeyValuePairs( FileEntry fileEntry) throws PortalException { if (!(fileEntry.getModel() instanceof DLFileEntry)) { return Collections.emptyList(); } List<KeyValuePair> keyValuePairs = new ArrayList<>(); FileVersion fileVersion = fileEntry.getFileVersion(); List<DDMStructure> ddmStructures = _ddmStructureLocalService.getClassStructures( fileEntry.getCompanyId(), _portal.getClassNameId(RawMetadataProcessor.class), StructureStructureKeyComparator.INSTANCE_DESCENDING); for (DDMStructure ddmStructure : ddmStructures) { DLFileEntryMetadata fileEntryMetadata = _dlFileEntryMetadataLocalService.fetchFileEntryMetadata( ddmStructure.getStructureId(), fileVersion.getFileVersionId()); if (fileEntryMetadata == null) { continue; } DDMFormValues ddmFormValues = _storageEngine.getDDMFormValues( fileEntryMetadata.getDDMStorageId()); if (ddmFormValues == null) { continue; } Map<String, List<DDMFormFieldValue>> ddmFormFieldValuesMap = ddmFormValues.getDDMFormFieldValuesMap(); Optional<String> tiffImageLengthOptional = _getDDMFormFieldsValueValue( ddmFormFieldValuesMap.get("TIFF_IMAGE_LENGTH")); tiffImageLengthOptional.ifPresent( tiffImageLength -> keyValuePairs.add( new KeyValuePair("og:image:height", tiffImageLength))); Optional<String> tiffImageWidthOptional = _getDDMFormFieldsValueValue( ddmFormFieldValuesMap.get("TIFF_IMAGE_WIDTH")); tiffImageWidthOptional.ifPresent( tiffImageWidth -> keyValuePairs.add( new KeyValuePair("og:image:width", tiffImageWidth))); } return keyValuePairs; } FileEntryMetadataOpenGraphTagsProvider(
		DDMStructureLocalService ddmStructureLocalService,
		DLFileEntryMetadataLocalService dlFileEntryMetadataLocalService,
		Portal portal, StorageEngine storageEngine); Iterable<KeyValuePair> getFileEntryMetadataOpenGraphTagKeyValuePairs(
			FileEntry fileEntry);  }
@Test public void testGetKeyValuePairsFileEntryWithEmptyTiffMetadata() throws Exception { Mockito.when( _fileEntry.getModel() ).thenReturn( Mockito.mock(DLFileEntry.class) ); Mockito.when( _fileEntry.getFileVersion() ).thenReturn( Mockito.mock(FileVersion.class) ); Mockito.when( _ddmStructureLocalService.getClassStructures( Mockito.anyLong(), Mockito.anyLong(), Mockito.any(OrderByComparator.class)) ).thenReturn( Collections.singletonList(Mockito.mock(DDMStructure.class)) ); Mockito.when( _dlFileEntryMetadataLocalService.fetchFileEntryMetadata( Mockito.anyLong(), Mockito.anyLong()) ).thenReturn( _dlFileEntryMetadata ); Mockito.when( _storageEngine.getDDMFormValues(Mockito.anyLong()) ).thenReturn( _ddmFormValues ); Mockito.when( _ddmFormValues.getDDMFormFieldValuesMap() ).thenReturn( Collections.singletonMap( "TIFF_IMAGE_LENGTH", Collections.emptyList()) ); Assert.assertEquals( Collections.emptyList(), _fileEntryMetadataOpenGraphTagsProvider. getFileEntryMetadataOpenGraphTagKeyValuePairs(_fileEntry)); }
@Test public void testGetKeyValuePairsFileEntryWithNoDDMFormValues() throws Exception { Mockito.when( _fileEntry.getModel() ).thenReturn( Mockito.mock(DLFileEntry.class) ); Mockito.when( _fileEntry.getFileVersion() ).thenReturn( Mockito.mock(FileVersion.class) ); Mockito.when( _ddmStructureLocalService.getClassStructures( Mockito.anyLong(), Mockito.anyLong(), Mockito.any(OrderByComparator.class)) ).thenReturn( Collections.singletonList(Mockito.mock(DDMStructure.class)) ); Mockito.when( _dlFileEntryMetadataLocalService.fetchFileEntryMetadata( Mockito.anyLong(), Mockito.anyLong()) ).thenReturn( _dlFileEntryMetadata ); Mockito.when( _storageEngine.getDDMFormValues(Mockito.anyLong()) ).thenReturn( null ); Assert.assertEquals( Collections.emptyList(), _fileEntryMetadataOpenGraphTagsProvider. getFileEntryMetadataOpenGraphTagKeyValuePairs(_fileEntry)); }
@Test public void testGetKeyValuePairsFileEntryWithNoDLFileEntryMetadata() throws Exception { Mockito.when( _fileEntry.getModel() ).thenReturn( Mockito.mock(DLFileEntry.class) ); Mockito.when( _fileEntry.getFileVersion() ).thenReturn( Mockito.mock(FileVersion.class) ); Mockito.when( _ddmStructureLocalService.getClassStructures( Mockito.anyLong(), Mockito.anyLong(), Mockito.any(OrderByComparator.class)) ).thenReturn( Collections.singletonList(Mockito.mock(DDMStructure.class)) ); Mockito.when( _dlFileEntryMetadataLocalService.fetchFileEntryMetadata( Mockito.anyLong(), Mockito.anyLong()) ).thenReturn( null ); Assert.assertEquals( Collections.emptyList(), _fileEntryMetadataOpenGraphTagsProvider. getFileEntryMetadataOpenGraphTagKeyValuePairs(_fileEntry)); }
@Test public void testGetKeyValuePairsFileEntryWithNoMetadata() throws Exception { Mockito.when( _fileEntry.getModel() ).thenReturn( Mockito.mock(DLFileEntry.class) ); Mockito.when( _fileEntry.getFileVersion() ).thenReturn( Mockito.mock(FileVersion.class) ); Mockito.when( _ddmStructureLocalService.getClassStructures( Mockito.anyLong(), Mockito.anyLong(), Mockito.any(OrderByComparator.class)) ).thenReturn( Collections.emptyList() ); Assert.assertEquals( Collections.emptyList(), _fileEntryMetadataOpenGraphTagsProvider. getFileEntryMetadataOpenGraphTagKeyValuePairs(_fileEntry)); }
@Test public void testGetKeyValuePairsFileEntryWithNoTiffMetadata() throws Exception { Mockito.when( _fileEntry.getModel() ).thenReturn( Mockito.mock(DLFileEntry.class) ); Mockito.when( _fileEntry.getFileVersion() ).thenReturn( Mockito.mock(FileVersion.class) ); Mockito.when( _ddmStructureLocalService.getClassStructures( Mockito.anyLong(), Mockito.anyLong(), Mockito.any(OrderByComparator.class)) ).thenReturn( Collections.singletonList(Mockito.mock(DDMStructure.class)) ); Mockito.when( _dlFileEntryMetadataLocalService.fetchFileEntryMetadata( Mockito.anyLong(), Mockito.anyLong()) ).thenReturn( _dlFileEntryMetadata ); Mockito.when( _storageEngine.getDDMFormValues(Mockito.anyLong()) ).thenReturn( _ddmFormValues ); Mockito.when( _ddmFormValues.getDDMFormFieldValuesMap() ).thenReturn( Collections.emptyMap() ); Assert.assertEquals( Collections.emptyList(), _fileEntryMetadataOpenGraphTagsProvider. getFileEntryMetadataOpenGraphTagKeyValuePairs(_fileEntry)); }
@Test public void testGetKeyValuePairsFileEntryWithTiffMetadata() throws Exception { Mockito.when( _fileEntry.getModel() ).thenReturn( Mockito.mock(DLFileEntry.class) ); Mockito.when( _fileEntry.getFileVersion() ).thenReturn( Mockito.mock(FileVersion.class) ); Mockito.when( _ddmStructureLocalService.getClassStructures( Mockito.anyLong(), Mockito.anyLong(), Mockito.any(OrderByComparator.class)) ).thenReturn( Collections.singletonList(Mockito.mock(DDMStructure.class)) ); Mockito.when( _dlFileEntryMetadataLocalService.fetchFileEntryMetadata( Mockito.anyLong(), Mockito.anyLong()) ).thenReturn( _dlFileEntryMetadata ); Mockito.when( _storageEngine.getDDMFormValues(Mockito.anyLong()) ).thenReturn( _ddmFormValues ); Mockito.when( _ddmFormValues.getDDMFormFieldValuesMap() ).thenReturn( Collections.singletonMap( "TIFF_IMAGE_LENGTH", Collections.singletonList(_ddmFormFieldValue)) ); Mockito.when( _ddmFormFieldValue.getValue() ).thenReturn( _value ); String expectedValue = StringUtil.randomString(); Mockito.when( _value.getString(Mockito.any(Locale.class)) ).thenReturn( expectedValue ); Assert.assertEquals( ListUtil.fromArray( new KeyValuePair("og:image:height", expectedValue)), _fileEntryMetadataOpenGraphTagsProvider. getFileEntryMetadataOpenGraphTagKeyValuePairs(_fileEntry)); }
@Test public void testGetKeyValuePairsNondlFileEntry() throws Exception { Assert.assertEquals( Collections.emptyList(), _fileEntryMetadataOpenGraphTagsProvider. getFileEntryMetadataOpenGraphTagKeyValuePairs(_fileEntry)); }