protected String extractDDMContent(DLFileVersion dlFileVersion, Locale locale) throws Exception { List<DLFileEntryMetadata> dlFileEntryMetadatas = DLFileEntryMetadataLocalServiceUtil.getFileVersionFileEntryMetadatas( dlFileVersion.getFileVersionId()); StringBundler sb = new StringBundler(dlFileEntryMetadatas.size()); for (DLFileEntryMetadata dlFileEntryMetadata : dlFileEntryMetadatas) { Fields fields = null; try { fields = StorageEngineUtil.getFields(dlFileEntryMetadata.getDDMStorageId()); } catch (Exception e) { } if (fields != null) { DDMStructure ddmStructure = DDMStructureLocalServiceUtil.getStructure(dlFileEntryMetadata.getDDMStructureId()); sb.append(DDMIndexerUtil.extractAttributes(ddmStructure, fields, locale)); } } return sb.toString(); }
protected void addFileEntryTypeAttributes(Document document, DLFileVersion dlFileVersion) throws PortalException, SystemException { DLFileEntryType dlFileEntryType = DLFileEntryTypeLocalServiceUtil.getDLFileEntryType(dlFileVersion.getFileEntryTypeId()); List<DDMStructure> ddmStructures = dlFileEntryType.getDDMStructures(); for (DDMStructure ddmStructure : ddmStructures) { Fields fields = null; try { DLFileEntryMetadata fileEntryMetadata = DLFileEntryMetadataLocalServiceUtil.getFileEntryMetadata( ddmStructure.getStructureId(), dlFileVersion.getFileVersionId()); fields = StorageEngineUtil.getFields(fileEntryMetadata.getDDMStorageId()); } catch (Exception e) { } if (fields != null) { DDMIndexerUtil.addAttributes(document, ddmStructure, fields); } } }
protected void sendDDMRecordFile( HttpServletRequest request, HttpServletResponse response, String[] pathArray) throws Exception { if (pathArray.length == 4) { String className = GetterUtil.getString(pathArray[1]); long classPK = GetterUtil.getLong(pathArray[2]); String fieldName = GetterUtil.getString(pathArray[3]); Field field = null; if (className.equals(DDLRecord.class.getName())) { DDLRecord ddlRecord = DDLRecordLocalServiceUtil.getRecord(classPK); field = ddlRecord.getField(fieldName); } else if (className.equals(DLFileEntryMetadata.class.getName())) { DLFileEntryMetadata fileEntryMetadata = DLFileEntryMetadataLocalServiceUtil.getDLFileEntryMetadata(classPK); Fields fields = StorageEngineUtil.getFields(fileEntryMetadata.getDDMStorageId()); field = fields.get(fieldName); } DDMUtil.sendFieldFile(request, response, field); } }
@Test public void testResetOriginalValues() throws Exception { if (!PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) { return; } DLFileEntryMetadata newDLFileEntryMetadata = addDLFileEntryMetadata(); _persistence.clearCache(); DLFileEntryMetadataModelImpl existingDLFileEntryMetadataModelImpl = (DLFileEntryMetadataModelImpl) _persistence.findByPrimaryKey(newDLFileEntryMetadata.getPrimaryKey()); Assert.assertEquals( existingDLFileEntryMetadataModelImpl.getDDMStructureId(), existingDLFileEntryMetadataModelImpl.getOriginalDDMStructureId()); Assert.assertEquals( existingDLFileEntryMetadataModelImpl.getFileVersionId(), existingDLFileEntryMetadataModelImpl.getOriginalFileVersionId()); Assert.assertEquals( existingDLFileEntryMetadataModelImpl.getFileEntryId(), existingDLFileEntryMetadataModelImpl.getOriginalFileEntryId()); Assert.assertEquals( existingDLFileEntryMetadataModelImpl.getFileVersionId(), existingDLFileEntryMetadataModelImpl.getOriginalFileVersionId()); }
@Override public Map<String, DDMFormValues> getDDMFormValuesMap(long fileVersionId) throws PortalException { Map<String, DDMFormValues> ddmFormValuesMap = new HashMap<>(); DLFileVersion dlFileVersion = DLFileVersionLocalServiceUtil.getFileVersion(fileVersionId); long fileEntryTypeId = dlFileVersion.getFileEntryTypeId(); if (fileEntryTypeId <= 0) { return ddmFormValuesMap; } DLFileEntryType dlFileEntryType = getDLFileEntryType(); List<DDMStructure> ddmStructures = dlFileEntryType.getDDMStructures(); for (DDMStructure ddmStructure : ddmStructures) { DLFileEntryMetadata dlFileEntryMetadata = DLFileEntryMetadataLocalServiceUtil.fetchFileEntryMetadata( ddmStructure.getStructureId(), fileVersionId); if (dlFileEntryMetadata != null) { DDMFormValues ddmFormValues = StorageEngineUtil.getDDMFormValues(dlFileEntryMetadata.getDDMStorageId()); ddmFormValuesMap.put(ddmStructure.getStructureKey(), ddmFormValues); } } return ddmFormValuesMap; }
@Test public void testFetchByPrimaryKeyExisting() throws Exception { DLFileEntryMetadata newDLFileEntryMetadata = addDLFileEntryMetadata(); DLFileEntryMetadata existingDLFileEntryMetadata = _persistence.fetchByPrimaryKey(newDLFileEntryMetadata.getPrimaryKey()); Assert.assertEquals(existingDLFileEntryMetadata, newDLFileEntryMetadata); }
@Test public void testCreate() throws Exception { long pk = ServiceTestUtil.nextLong(); DLFileEntryMetadata dlFileEntryMetadata = _persistence.create(pk); Assert.assertNotNull(dlFileEntryMetadata); Assert.assertEquals(dlFileEntryMetadata.getPrimaryKey(), pk); }
@Test public void testRemove() throws Exception { DLFileEntryMetadata newDLFileEntryMetadata = addDLFileEntryMetadata(); _persistence.remove(newDLFileEntryMetadata); DLFileEntryMetadata existingDLFileEntryMetadata = _persistence.fetchByPrimaryKey(newDLFileEntryMetadata.getPrimaryKey()); Assert.assertNull(existingDLFileEntryMetadata); }
protected void exportMetaData( PortletDataContext portletDataContext, Element fileEntryElement, FileEntry fileEntry) throws Exception { LiferayFileEntry liferayFileEntry = (LiferayFileEntry) fileEntry; DLFileEntry dlFileEntry = liferayFileEntry.getDLFileEntry(); long fileEntryTypeId = dlFileEntry.getFileEntryTypeId(); DLFileEntryType dlFileEntryType = DLFileEntryTypeLocalServiceUtil.fetchFileEntryType(fileEntryTypeId); if ((dlFileEntryType == null) || !dlFileEntryType.isExportable()) { return; } StagedModelDataHandlerUtil.exportReferenceStagedModel( portletDataContext, fileEntry, dlFileEntryType, PortletDataContext.REFERENCE_TYPE_STRONG); List<DDMStructure> ddmStructures = dlFileEntryType.getDDMStructures(); for (DDMStructure ddmStructure : ddmStructures) { FileVersion fileVersion = fileEntry.getFileVersion(); DLFileEntryMetadata dlFileEntryMetadata = DLFileEntryMetadataLocalServiceUtil.fetchFileEntryMetadata( ddmStructure.getStructureId(), fileVersion.getFileVersionId()); if (dlFileEntryMetadata == null) { continue; } Element structureFields = fileEntryElement.addElement("structure-fields"); String path = ExportImportPathUtil.getModelPath( ddmStructure, String.valueOf(dlFileEntryMetadata.getDDMStorageId())); structureFields.addAttribute("path", path); structureFields.addAttribute("structureUuid", ddmStructure.getUuid()); DDMFormValues ddmFormValues = StorageEngineUtil.getDDMFormValues(dlFileEntryMetadata.getDDMStorageId()); portletDataContext.addZipEntry(path, ddmFormValues); } }
@Test public void testDynamicQueryByPrimaryKeyExisting() throws Exception { DLFileEntryMetadata newDLFileEntryMetadata = addDLFileEntryMetadata(); DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass( DLFileEntryMetadata.class, DLFileEntryMetadata.class.getClassLoader()); dynamicQuery.add( RestrictionsFactoryUtil.eq( "fileEntryMetadataId", newDLFileEntryMetadata.getFileEntryMetadataId())); List<DLFileEntryMetadata> result = _persistence.findWithDynamicQuery(dynamicQuery); Assert.assertEquals(1, result.size()); DLFileEntryMetadata existingDLFileEntryMetadata = result.get(0); Assert.assertEquals(existingDLFileEntryMetadata, newDLFileEntryMetadata); }
protected void addFileEntryTypeAttributes(Document document, DLFileVersion dlFileVersion) throws PortalException { List<DLFileEntryMetadata> dlFileEntryMetadatas = DLFileEntryMetadataLocalServiceUtil.getFileVersionFileEntryMetadatas( dlFileVersion.getFileVersionId()); for (DLFileEntryMetadata dlFileEntryMetadata : dlFileEntryMetadatas) { Fields fields = null; try { fields = StorageEngineUtil.getFields(dlFileEntryMetadata.getDDMStorageId()); } catch (Exception e) { } if (fields != null) { DDMStructure ddmStructure = DDMStructureLocalServiceUtil.getStructure(dlFileEntryMetadata.getDDMStructureId()); DDMIndexerUtil.addAttributes(document, ddmStructure, fields); } } }
@Test public void testDynamicQueryByProjectionExisting() throws Exception { DLFileEntryMetadata newDLFileEntryMetadata = addDLFileEntryMetadata(); DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass( DLFileEntryMetadata.class, DLFileEntryMetadata.class.getClassLoader()); dynamicQuery.setProjection(ProjectionFactoryUtil.property("fileEntryMetadataId")); Object newFileEntryMetadataId = newDLFileEntryMetadata.getFileEntryMetadataId(); dynamicQuery.add( RestrictionsFactoryUtil.in("fileEntryMetadataId", new Object[] {newFileEntryMetadataId})); List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery); Assert.assertEquals(1, result.size()); Object existingFileEntryMetadataId = result.get(0); Assert.assertEquals(existingFileEntryMetadataId, newFileEntryMetadataId); }
protected DLFileEntryMetadata addDLFileEntryMetadata() throws Exception { long pk = ServiceTestUtil.nextLong(); DLFileEntryMetadata dlFileEntryMetadata = _persistence.create(pk); dlFileEntryMetadata.setUuid(ServiceTestUtil.randomString()); dlFileEntryMetadata.setDDMStorageId(ServiceTestUtil.nextLong()); dlFileEntryMetadata.setDDMStructureId(ServiceTestUtil.nextLong()); dlFileEntryMetadata.setFileEntryTypeId(ServiceTestUtil.nextLong()); dlFileEntryMetadata.setFileEntryId(ServiceTestUtil.nextLong()); dlFileEntryMetadata.setFileVersionId(ServiceTestUtil.nextLong()); _persistence.update(dlFileEntryMetadata, false); return dlFileEntryMetadata; }
@Test public void testUpdateExisting() throws Exception { long pk = ServiceTestUtil.nextLong(); DLFileEntryMetadata newDLFileEntryMetadata = _persistence.create(pk); newDLFileEntryMetadata.setUuid(ServiceTestUtil.randomString()); newDLFileEntryMetadata.setDDMStorageId(ServiceTestUtil.nextLong()); newDLFileEntryMetadata.setDDMStructureId(ServiceTestUtil.nextLong()); newDLFileEntryMetadata.setFileEntryTypeId(ServiceTestUtil.nextLong()); newDLFileEntryMetadata.setFileEntryId(ServiceTestUtil.nextLong()); newDLFileEntryMetadata.setFileVersionId(ServiceTestUtil.nextLong()); _persistence.update(newDLFileEntryMetadata, false); DLFileEntryMetadata existingDLFileEntryMetadata = _persistence.findByPrimaryKey(newDLFileEntryMetadata.getPrimaryKey()); Assert.assertEquals(existingDLFileEntryMetadata.getUuid(), newDLFileEntryMetadata.getUuid()); Assert.assertEquals( existingDLFileEntryMetadata.getFileEntryMetadataId(), newDLFileEntryMetadata.getFileEntryMetadataId()); Assert.assertEquals( existingDLFileEntryMetadata.getDDMStorageId(), newDLFileEntryMetadata.getDDMStorageId()); Assert.assertEquals( existingDLFileEntryMetadata.getDDMStructureId(), newDLFileEntryMetadata.getDDMStructureId()); Assert.assertEquals( existingDLFileEntryMetadata.getFileEntryTypeId(), newDLFileEntryMetadata.getFileEntryTypeId()); Assert.assertEquals( existingDLFileEntryMetadata.getFileEntryId(), newDLFileEntryMetadata.getFileEntryId()); Assert.assertEquals( existingDLFileEntryMetadata.getFileVersionId(), newDLFileEntryMetadata.getFileVersionId()); }