Example usage for com.liferay.portal.kernel.repository.model FileVersion getStatus

List of usage examples for com.liferay.portal.kernel.repository.model FileVersion getStatus

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.repository.model FileVersion getStatus.

Prototype

public int getStatus();

Source Link

Usage

From source file:com.custom.portal.verify.CustomVerifyDynamicDataMapping.java

License:Open Source License

protected void updateDLFileUploadReferences(long dlFileEntryMetadataId) throws Exception {

    DLFileEntryMetadata dlFileEntryMetadata = DLFileEntryMetadataLocalServiceUtil
            .getFileEntryMetadata(dlFileEntryMetadataId);

    FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(dlFileEntryMetadata.getFileEntryId());

    FileVersion fileVersion = fileEntry.getFileVersion();

    updateFileUploadReferences(fileEntry.getCompanyId(), dlFileEntryMetadata.getDDMStorageId(),
            fileEntry.getUserId(), fileEntry.getGroupId(), dlFileEntryMetadata, fileVersion.getStatus());
}

From source file:com.liferay.adaptive.media.image.internal.handler.AMImageRequestHandler.java

License:Open Source License

private Optional<Tuple<FileVersion, AMImageAttributeMapping>> _interpretPath(String pathInfo) {

    try {// w w w . j  a v  a 2  s. c  o  m
        Optional<Tuple<FileVersion, Map<String, String>>> fileVersionPropertiesTupleOptional = _pathInterpreter
                .interpretPath(pathInfo);

        if (!fileVersionPropertiesTupleOptional.isPresent()) {
            return Optional.empty();
        }

        Tuple<FileVersion, Map<String, String>> fileVersionMapTuple = fileVersionPropertiesTupleOptional.get();

        FileVersion fileVersion = fileVersionMapTuple.first;

        if (fileVersion.getStatus() == WorkflowConstants.STATUS_IN_TRASH) {
            return Optional.empty();
        }

        Map<String, String> properties = fileVersionMapTuple.second;

        AMAttribute<Object, Long> contentLengthAMAttribute = AMAttribute.getContentLengthAMAttribute();

        properties.put(contentLengthAMAttribute.getName(), String.valueOf(fileVersion.getSize()));

        AMAttribute<Object, String> contentTypeAMAttribute = AMAttribute.getContentTypeAMAttribute();

        properties.put(contentTypeAMAttribute.getName(), fileVersion.getMimeType());

        AMAttribute<Object, String> fileNameAMAttribute = AMAttribute.getFileNameAMAttribute();

        properties.put(fileNameAMAttribute.getName(), fileVersion.getFileName());

        AMImageAttributeMapping amImageAttributeMapping = AMImageAttributeMapping.fromProperties(properties);

        return Optional.of(Tuple.of(fileVersion, amImageAttributeMapping));
    } catch (AMRuntimeException | NumberFormatException e) {
        _log.error(e);

        return Optional.empty();
    }
}

From source file:com.liferay.document.library.internal.exportimport.data.handler.FileEntryStagedModelDataHandler.java

License:Open Source License

@Override
protected void validateExport(PortletDataContext portletDataContext, FileEntry fileEntry)
        throws PortletDataException {

    if ((fileEntry.getGroupId() != portletDataContext.getGroupId())
            && (fileEntry.getGroupId() != portletDataContext.getScopeGroupId())) {

        PortletDataException pde = new PortletDataException(PortletDataException.INVALID_GROUP);

        pde.setStagedModel(fileEntry);/*from  w w  w.  j a  va2  s .c  om*/

        throw pde;
    }

    try {
        FileVersion fileVersion = fileEntry.getFileVersion();

        if (!portletDataContext.isInitialPublication()
                && !ArrayUtil.contains(getExportableStatuses(), fileVersion.getStatus())) {

            throw new PortletDataException(PortletDataException.STATUS_UNAVAILABLE);
        }
    } catch (PortletDataException pde) {
        throw pde;
    } catch (Exception e) {
        if (_log.isDebugEnabled()) {
            _log.debug(e, e);
        } else if (_log.isWarnEnabled()) {
            _log.warn("Unable to check workflow status for file entry " + fileEntry.getFileEntryId());
        }
    }

    if (fileEntry.isInTrash() || fileEntry.isInTrashContainer()) {
        PortletDataException pde = new PortletDataException(PortletDataException.STATUS_IN_TRASH);

        pde.setStagedModel(fileEntry);

        throw pde;
    }
}

From source file:com.liferay.document.library.internal.exportimport.data.handler.test.FileEntryStagedModelDataHandlerTest.java

License:Open Source License

@Override
protected void validateImportedStagedModel(StagedModel stagedModel, StagedModel importedStagedModel)
        throws Exception {

    Assert.assertTrue(/*from w  w  w  . java2 s.c o m*/
            String.valueOf(stagedModel.getCreateDate()) + StringPool.SPACE
                    + importedStagedModel.getCreateDate(),
            DateUtil.equals(stagedModel.getCreateDate(), importedStagedModel.getCreateDate()));

    Assert.assertEquals(stagedModel.getUuid(), importedStagedModel.getUuid());

    FileEntry fileEntry = (FileEntry) stagedModel;
    FileEntry importedFileEntry = (FileEntry) importedStagedModel;

    Assert.assertEquals(fileEntry.getFileName(), importedFileEntry.getFileName());
    Assert.assertEquals(fileEntry.getExtension(), importedFileEntry.getExtension());
    Assert.assertEquals(fileEntry.getMimeType(), importedFileEntry.getMimeType());
    Assert.assertEquals(fileEntry.getTitle(), importedFileEntry.getTitle());
    Assert.assertEquals(fileEntry.getDescription(), importedFileEntry.getDescription());
    Assert.assertEquals(fileEntry.getSize(), importedFileEntry.getSize());

    FileVersion latestFileVersion = fileEntry.getLatestFileVersion();
    FileVersion importedLatestFileVersion = importedFileEntry.getLatestFileVersion();

    Assert.assertEquals(latestFileVersion.getUuid(), importedLatestFileVersion.getUuid());
    Assert.assertEquals(latestFileVersion.getFileName(), importedLatestFileVersion.getFileName());
    Assert.assertEquals(latestFileVersion.getExtension(), importedLatestFileVersion.getExtension());
    Assert.assertEquals(latestFileVersion.getMimeType(), importedLatestFileVersion.getMimeType());
    Assert.assertEquals(latestFileVersion.getTitle(), importedLatestFileVersion.getTitle());
    Assert.assertEquals(latestFileVersion.getDescription(), importedLatestFileVersion.getDescription());
    Assert.assertEquals(latestFileVersion.getSize(), importedLatestFileVersion.getSize());
    Assert.assertEquals(latestFileVersion.getStatus(), importedLatestFileVersion.getStatus());
}

From source file:com.liferay.item.selector.taglib.internal.util.ItemSelectorRepositoryEntryBrowserUtil.java

License:Open Source License

public static JSONObject getItemMetadataJSONObject(FileEntry fileEntry, Locale locale) throws PortalException {

    JSONObject itemMetadataJSONObject = JSONFactoryUtil.createJSONObject();

    JSONArray groupsJSONArray = JSONFactoryUtil.createJSONArray();

    JSONObject firstTabJSONObject = JSONFactoryUtil.createJSONObject();

    JSONArray firstTabDataJSONArray = JSONFactoryUtil.createJSONArray();

    FileVersion latestFileVersion = fileEntry.getLatestFileVersion();

    firstTabDataJSONArray.put(_createJSONObject(LanguageUtil.get(locale, "format"),
            HtmlUtil.escape(latestFileVersion.getExtension())));

    firstTabDataJSONArray.put(_createJSONObject(LanguageUtil.get(locale, "size"),
            TextFormatter.formatStorageSize(fileEntry.getSize(), locale)));
    firstTabDataJSONArray.put(_createJSONObject(LanguageUtil.get(locale, "name"),
            HtmlUtil.escape(DLUtil.getTitleWithExtension(fileEntry))));

    Date modifiedDate = fileEntry.getModifiedDate();

    firstTabDataJSONArray.put(_createJSONObject(LanguageUtil.get(locale, "modified"),
            LanguageUtil.format(locale, "x-ago-by-x",
                    new Object[] {
                            LanguageUtil.getTimeDescription(locale,
                                    System.currentTimeMillis() - modifiedDate.getTime(), true),
                            HtmlUtil.escape(fileEntry.getUserName()) })));

    firstTabJSONObject.put("data", firstTabDataJSONArray);

    firstTabJSONObject.put("title", LanguageUtil.get(locale, "file-info"));

    groupsJSONArray.put(firstTabJSONObject);

    JSONObject secondTabJSONObject = JSONFactoryUtil.createJSONObject();

    JSONArray secondTabDataJSONArray = JSONFactoryUtil.createJSONArray();

    secondTabDataJSONArray.put(_createJSONObject(LanguageUtil.get(locale, "version"),
            HtmlUtil.escape(latestFileVersion.getVersion())));
    secondTabDataJSONArray.put(_createJSONObject(LanguageUtil.get(locale, "status"),
            WorkflowConstants.getStatusLabel(latestFileVersion.getStatus())));

    secondTabJSONObject.put("data", secondTabDataJSONArray);

    secondTabJSONObject.put("title", LanguageUtil.get(locale, "version"));

    groupsJSONArray.put(secondTabJSONObject);

    itemMetadataJSONObject.put("groups", groupsJSONArray);

    return itemMetadataJSONObject;
}

From source file:com.liferay.portlet.documentlibrary.lar.DLPortletDataHandlerImpl.java

License:Open Source License

public static void exportFileEntry(PortletDataContext portletDataContext, Element fileEntryTypesElement,
        Element foldersElement, Element fileEntriesElement, Element fileRanksElement,
        Element repositoriesElement, Element repositoryEntriesElement, FileEntry fileEntry,
        boolean checkDateRange) throws Exception {

    if (checkDateRange && !portletDataContext.isWithinDateRange(fileEntry.getModifiedDate())) {

        return;//from ww  w  .j av  a  2 s.  c om
    }

    if (!fileEntry.isDefaultRepository()) {
        Repository repository = RepositoryUtil.findByPrimaryKey(fileEntry.getRepositoryId());

        exportRepository(portletDataContext, repositoriesElement, repositoryEntriesElement, repository);

        return;
    }

    FileVersion fileVersion = fileEntry.getFileVersion();

    if (fileVersion.getStatus() != WorkflowConstants.STATUS_APPROVED) {
        return;
    }

    String path = getFileEntryPath(portletDataContext, fileEntry);

    if (!portletDataContext.isPathNotProcessed(path)) {
        return;
    }

    Element fileEntryElement = fileEntriesElement.addElement("file-entry");

    if (foldersElement != null) {
        exportParentFolder(portletDataContext, fileEntryTypesElement, foldersElement, repositoriesElement,
                repositoryEntriesElement, fileEntry.getFolderId());
    }

    if (!portletDataContext.isPerformDirectBinaryImport()) {
        InputStream is = null;

        try {
            is = FileEntryUtil.getContentStream(fileEntry);
        } catch (NoSuchFileException nsfe) {
        }

        if (is == null) {
            if (_log.isWarnEnabled()) {
                _log.warn("No file found for file entry " + fileEntry.getFileEntryId());
            }

            fileEntryElement.detach();

            return;
        }

        try {
            String binPath = getFileEntryBinPath(portletDataContext, fileEntry);

            portletDataContext.addZipEntry(binPath, is);

            fileEntryElement.addAttribute("bin-path", binPath);
        } finally {
            try {
                is.close();
            } catch (IOException ioe) {
                _log.error(ioe, ioe);
            }
        }
    }

    if (portletDataContext.getBooleanParameter(_NAMESPACE, "ranks")) {
        List<DLFileRank> fileRanks = DLFileRankUtil.findByFileEntryId(fileEntry.getFileEntryId());

        for (DLFileRank fileRank : fileRanks) {
            exportFileRank(portletDataContext, fileRanksElement, fileRank);
        }
    }

    if (portletDataContext.getBooleanParameter(_NAMESPACE, "previews-and-thumbnails")) {

        DLProcessorRegistryUtil.exportGeneratedFiles(portletDataContext, fileEntry, fileEntryElement);
    }

    exportMetaData(portletDataContext, fileEntryTypesElement, fileEntryElement, fileEntry);

    portletDataContext.addClassedModel(fileEntryElement, path, fileEntry, _NAMESPACE);
}