Example usage for com.liferay.portal.kernel.repository.model FileEntry getTitle

List of usage examples for com.liferay.portal.kernel.repository.model FileEntry getTitle

Introduction

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

Prototype

public String getTitle();

Source Link

Usage

From source file:au.com.permeance.liferay.portlet.documentlibrary.service.impl.DLFolderExportZipHelper.java

License:Open Source License

/**
 * Returns a ZIP entry name for the file entry.
 * //from ww  w. j  a  v a 2  s .co  m
 * @param fileEntry file entry
 * @param folderPath file path
 * @param zipWriter ZIP writer
 * 
 * @return ZIP entry name
 * 
 * @throws SystemException
 * @throws PortalException
 */
public static String buildZipEntryName(FileEntry fileEntry, String folderPath, ZipWriter zipWriter)
        throws SystemException, PortalException {

    // Use file entry title as file name
    String fileEntryBaseName = fileEntry.getTitle();

    // normalize base name by stripping extension and replacing non-alphanum chars with underscore
    fileEntryBaseName = FilenameUtils.getBaseName(fileEntryBaseName);
    fileEntryBaseName = fileEntryBaseName.replaceAll("\\W+", "_");

    // build zip entry name
    String zipEntryName = folderPath + fileEntryBaseName + FilenameUtils.EXTENSION_SEPARATOR_STR
            + fileEntry.getExtension();

    if (zipWriter.hasAllocatedPath(zipEntryName)) {
        String oldZipEntryName = zipEntryName;
        int counter = 1;
        while (true) {
            zipEntryName = folderPath + fileEntryBaseName + StringPool.OPEN_BRACKET + counter
                    + StringPool.CLOSE_BRACKET + FilenameUtils.EXTENSION_SEPARATOR_STR
                    + fileEntry.getExtension();
            if (!zipWriter.hasAllocatedPath(zipEntryName)) {
                break;
            }
            counter++;
        }

        if (s_log.isDebugEnabled()) {
            s_log.debug(oldZipEntryName + " already exists in ZIP file, renaming to " + zipEntryName);
        }
    }

    return zipEntryName;
}

From source file:au.com.permeance.liferay.portlet.documentlibrary.service.impl.DLFolderUsageHelper.java

License:Open Source License

/**
 * Visit File Entry.//from w  w w .  j  a v  a  2s.  co m
 *
 * @param fileEntry file entry
 * @param folderPath folder path
 * @param folderUsageCollector folder usage collector
 * 
 * @throws PortalException
 * @throws SystemException
 * @throws IOException
 */
public static void calculateFileEntryUsage(FileEntry fileEntry, String folderPath,
        DLFolderUsageCollector folderUsageCollector) throws PortalException, SystemException, IOException {

    if (s_log.isDebugEnabled()) {
        s_log.debug(
                "calculating usage for file entry " + fileEntry.getFileEntryId() + "/" + fileEntry.getTitle());
    }

    try {

        long fileEntrySize = fileEntry.getSize();

        folderUsageCollector.incrementFolderSize(fileEntrySize);

    } catch (Exception e) {

        String msg = "Error calculating usage for file entry " + fileEntry.getFileEntryId() + " : "
                + e.getMessage();

        s_log.error(msg, e);

        if (e instanceof PortalException) {
            throw (PortalException) e;

        } else if (e instanceof SystemException) {
            throw (SystemException) e;

        } else if (e instanceof IOException) {
            throw (IOException) e;
        }
    }
}

From source file:com.fmdp.webform.portlet.WebFormPortlet.java

License:Open Source License

public void saveData(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
    ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

    String portletId = PortalUtil.getPortletId(actionRequest);

    PortletPreferences preferences = PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletId);

    boolean requireCaptcha = GetterUtil.getBoolean(preferences.getValue("requireCaptcha", StringPool.BLANK));
    String successURL = GetterUtil.getString(preferences.getValue("successURL", StringPool.BLANK));
    boolean sendAsEmail = GetterUtil.getBoolean(preferences.getValue("sendAsEmail", StringPool.BLANK));
    boolean sendThanksEmail = GetterUtil.getBoolean(preferences.getValue("sendThanksEmail", StringPool.BLANK));
    boolean saveToDatabase = GetterUtil.getBoolean(preferences.getValue("saveToDatabase", StringPool.BLANK));
    String databaseTableName = GetterUtil
            .getString(preferences.getValue("databaseTableName", StringPool.BLANK));
    boolean saveToFile = GetterUtil.getBoolean(preferences.getValue("saveToFile", StringPool.BLANK));
    boolean uploadToDisk = GetterUtil.getBoolean(preferences.getValue("uploadToDisk", StringPool.BLANK));
    boolean uploadToDM = GetterUtil.getBoolean(preferences.getValue("uploadToDM", StringPool.BLANK));
    long newFolderId = GetterUtil.getLong(preferences.getValue("newFolderId", StringPool.BLANK));
    String fileName = GetterUtil.getString(preferences.getValue("fileName", StringPool.BLANK));
    String uploadDiskDir = GetterUtil.getString(preferences.getValue("uploadDiskDir", StringPool.BLANK));

    if (requireCaptcha) {
        try {/*  w w w. j ava  2 s. co  m*/
            CaptchaUtil.check(actionRequest);
        } catch (CaptchaTextException cte) {
            SessionErrors.add(actionRequest, CaptchaTextException.class.getName());

            return;
        }
    }

    UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    Map<String, String> fieldsMap = new LinkedHashMap<String, String>();

    String fileAttachment = "";

    for (int i = 1; true; i++) {
        String fieldLabel = preferences.getValue("fieldLabel" + i, StringPool.BLANK);

        String fieldType = preferences.getValue("fieldType" + i, StringPool.BLANK);

        if (Validator.isNull(fieldLabel)) {
            break;
        }

        if (StringUtil.equalsIgnoreCase(fieldType, "paragraph")) {
            continue;
        }
        if (StringUtil.equalsIgnoreCase(fieldType, "file")) {
            if (_log.isDebugEnabled()) {
                _log.debug("Field name for file: " + fieldLabel);
            }

            File file = uploadRequest.getFile("field" + i);

            String sourceFileName = uploadRequest.getFileName("field" + i);
            if (_log.isDebugEnabled()) {
                _log.debug("File attachment: " + sourceFileName);
            }
            JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

            if (Validator.isNotNull(sourceFileName) && !"".equals(sourceFileName)) {

                if (uploadRequest.getSize("field" + i) == 0) {
                    SessionErrors.add(actionRequest, "uploadToDiskError", "Uploaded file size is 0");
                    if (_log.isDebugEnabled()) {
                        _log.debug("Uploaded file size is 0");
                    }
                    return;
                }
                //               List<String> uploadResults = new ArrayList<String>();
                String uploadResult = "";
                if (uploadToDisk) {
                    uploadResult = uploadFile(file, sourceFileName, uploadDiskDir);
                    if (uploadResult.equalsIgnoreCase("File Upload Error")) {
                        SessionErrors.add(actionRequest, "uploadToDiskError", uploadResult);
                        return;
                    }
                    fileAttachment = uploadDiskDir + File.separator + uploadResult;
                    //uploadResults.add(uploadResult);
                    jsonObject.put("fsOriginalName", sourceFileName);
                    jsonObject.put("fsName", uploadResult);
                }
                if (uploadToDM) {
                    uploadResult = "";
                    String contentType = MimeTypesUtil.getContentType(file);
                    Folder folderName = DLAppLocalServiceUtil.getFolder(newFolderId);
                    if (_log.isDebugEnabled()) {
                        _log.debug("DM Folder: " + folderName.getName());
                    }
                    InputStream inputStream = new FileInputStream(file);
                    long repositoryId = folderName.getRepositoryId();
                    try {
                        String selectedFileName = sourceFileName;
                        while (true) {
                            try {
                                DLAppLocalServiceUtil.getFileEntry(themeDisplay.getScopeGroupId(), newFolderId,
                                        selectedFileName);

                                StringBundler sb = new StringBundler(5);

                                sb.append(FileUtil.stripExtension(selectedFileName));
                                sb.append(StringPool.DASH);
                                sb.append(StringUtil.randomString());
                                sb.append(StringPool.PERIOD);
                                sb.append(FileUtil.getExtension(selectedFileName));

                                selectedFileName = sb.toString();
                            } catch (Exception e) {
                                break;
                            }
                        }

                        FileEntry fileEntry = DLAppLocalServiceUtil.addFileEntry(themeDisplay.getUserId(),
                                repositoryId, newFolderId, selectedFileName, //file.getName(), 
                                contentType, selectedFileName, "", "", inputStream, file.length(),
                                serviceContext);
                        if (_log.isDebugEnabled()) {
                            _log.debug("DM file uploade: " + fileEntry.getTitle());
                        }
                        //Map<String, Serializable> workflowContext = new HashMap<String, Serializable>();
                        //workflowContext.put("event",DLSyncConstants.EVENT_UPDATE);
                        //DLFileEntryLocalServiceUtil.updateStatus(themeDisplay.getUserId(), fileEntry.getFileVersion().getFileVersionId(), WorkflowConstants.STATUS_APPROVED, workflowContext, serviceContext);
                        uploadResult = String.valueOf(fileEntry.getFileEntryId());
                        //uploadResults.add(uploadResult);
                        String docUrl = themeDisplay.getPortalURL() + "/c/document_library/get_file?uuid="
                                + fileEntry.getUuid() + "&groupId=" + themeDisplay.getScopeGroupId();
                        jsonObject.put("fe", uploadResult);
                        jsonObject.put("feOriginalName", sourceFileName);
                        jsonObject.put("feName", fileEntry.getTitle());
                        jsonObject.put("feUrl", docUrl);
                    } catch (PortalException pe) {
                        SessionErrors.add(actionRequest, "uploadToDmError");
                        _log.error("The upload to DM failed", pe);
                        return;
                    } catch (Exception e) {
                        _log.error("The upload to DM failed", e);
                        return;
                    }
                }
                jsonObject.put("Status", "With Attachment");
            } else {
                jsonObject.put("Status", "No Attachment");
            }
            fieldsMap.put(fieldLabel, jsonObject.toString());
        } else {
            fieldsMap.put(fieldLabel, uploadRequest.getParameter("field" + i));
        }
    }

    Set<String> validationErrors = null;

    try {
        validationErrors = validate(fieldsMap, preferences);
    } catch (Exception e) {
        SessionErrors.add(actionRequest, "validationScriptError", e.getMessage().trim());

        return;
    }

    User currentUser = PortalUtil.getUser(actionRequest);
    String userEmail = "";
    if (!Validator.isNull(currentUser)) {
        userEmail = currentUser.getEmailAddress();
        if (_log.isDebugEnabled()) {
            _log.debug("User email for the form author: " + userEmail);
        }

        fieldsMap.put("email-from", userEmail);
    } else {
        fieldsMap.put("email-from", "guest");
    }

    DateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
    df.setTimeZone(TimeZone.getTimeZone(themeDisplay.getTimeZone().getID()));
    Date dateobj = new Date();
    fieldsMap.put("email-sent-on", df.format(dateobj));

    if (validationErrors.isEmpty()) {
        boolean emailSuccess = true;
        boolean databaseSuccess = true;
        boolean fileSuccess = true;
        boolean emailThanksSuccess = true;

        if (sendAsEmail) {
            emailSuccess = WebFormUtil.sendEmail(themeDisplay.getCompanyId(), fieldsMap, preferences,
                    fileAttachment);
        }

        if (sendThanksEmail && !Validator.isNull(currentUser)) {
            emailThanksSuccess = WebFormUtil.sendThanksEmail(themeDisplay.getCompanyId(), fieldsMap,
                    preferences, userEmail);
        }

        if (saveToDatabase) {
            if (Validator.isNull(databaseTableName)) {
                databaseTableName = WebFormUtil.getNewDatabaseTableName(portletId);

                preferences.setValue("databaseTableName", databaseTableName);

                preferences.store();
            }

            databaseSuccess = saveDatabase(themeDisplay.getCompanyId(), fieldsMap, preferences,
                    databaseTableName);
        }

        if (saveToFile) {
            fileSuccess = saveFile(fieldsMap, fileName);
        }

        if (emailSuccess && emailThanksSuccess && databaseSuccess && fileSuccess) {
            if (Validator.isNull(successURL)) {
                SessionMessages.add(actionRequest, "success");
            } else {
                SessionMessages.add(actionRequest,
                        portletId + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE);
            }
        } else {
            SessionErrors.add(actionRequest, "error");
        }
    } else {
        for (String badField : validationErrors) {
            SessionErrors.add(actionRequest, "error" + badField);
        }
    }

    if (SessionErrors.isEmpty(actionRequest) && Validator.isNotNull(successURL)) {

        actionResponse.sendRedirect(successURL);
    }
}

From source file:com.liferay.adaptive.media.image.item.selector.internal.resolver.test.FileEntryAdaptiveMediaImageURLItemSelectorReturnTypeResolverTest.java

License:Open Source License

@Test
public void testAddingFileEntryWithHDMediaQueries() throws Exception {
    try (DestinationReplacer destinationReplacer = new DestinationReplacer(
            "liferay/adaptive_media_processor")) {

        _addTestVariant("small", "uuid0", 50, 50);
        _addTestVariant("small.hd", "uuid1", 100, 100);
        _addTestVariant("medium", "uuid2", 300, 300);

        ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group,
                TestPropsValues.getUserId());

        final FileEntry fileEntry = _addImageFileEntry(serviceContext);

        String value = _resolver.getValue(fileEntry, null);

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject(value);

        String defaultSource = jsonObject.getString("defaultSource");

        Assert.assertEquals(DLUtil.getPreviewURL(fileEntry, fileEntry.getFileVersion(), null, StringPool.BLANK,
                false, false), defaultSource);

        JSONArray sourcesJSONArray = jsonObject.getJSONArray("sources");

        Assert.assertEquals(3, sourcesJSONArray.length());

        _assertHDSrcSource(sourcesJSONArray.getJSONObject(0), fileEntry.getFileEntryId(), "uuid0", "uuid1",
                fileEntry.getTitle());
        _assertSrcSource(sourcesJSONArray.getJSONObject(1), fileEntry.getFileEntryId(), "uuid1",
                fileEntry.getTitle());// w ww.  ja v a  2 s  .c o m
        _assertSrcSource(sourcesJSONArray.getJSONObject(2), fileEntry.getFileEntryId(), "uuid2",
                fileEntry.getTitle());

        _assertAttibutes(sourcesJSONArray.getJSONObject(0), 50, 0);
        _assertAttibutes(sourcesJSONArray.getJSONObject(1), 100, 50);
        _assertAttibutes(sourcesJSONArray.getJSONObject(2), 300, 100);
    }
}

From source file:com.liferay.adaptive.media.image.item.selector.internal.resolver.test.FileEntryAdaptiveMediaImageURLItemSelectorReturnTypeResolverTest.java

License:Open Source License

@Test
public void testAddingFileEntryWithImageCreatesMedia() throws Exception {
    try (DestinationReplacer destinationReplacer = new DestinationReplacer(
            "liferay/adaptive_media_processor")) {

        _addTestVariant("small", "uuid0", 50, 50);
        _addTestVariant("big", "uuid1", 400, 280);
        _addTestVariant("medium", "uuid2", 300, 200);
        _addTestVariant("extra", "uuid3", 500, 330);

        ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group,
                TestPropsValues.getUserId());

        final FileEntry fileEntry = _addImageFileEntry(serviceContext);

        String value = _resolver.getValue(fileEntry, null);

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject(value);

        String defaultSource = jsonObject.getString("defaultSource");

        Assert.assertEquals(DLUtil.getPreviewURL(fileEntry, fileEntry.getFileVersion(), null, StringPool.BLANK,
                false, false), defaultSource);

        JSONArray sourcesJSONArray = jsonObject.getJSONArray("sources");

        Assert.assertEquals(4, sourcesJSONArray.length());

        _assertSrcSource(sourcesJSONArray.getJSONObject(0), fileEntry.getFileEntryId(), "uuid0",
                fileEntry.getTitle());
        _assertSrcSource(sourcesJSONArray.getJSONObject(1), fileEntry.getFileEntryId(), "uuid2",
                fileEntry.getTitle());/*w  w w  .j a v a  2  s. c om*/
        _assertSrcSource(sourcesJSONArray.getJSONObject(2), fileEntry.getFileEntryId(), "uuid1",
                fileEntry.getTitle());
        _assertSrcSource(sourcesJSONArray.getJSONObject(3), fileEntry.getFileEntryId(), "uuid3",
                fileEntry.getTitle());

        _assertAttibutes(sourcesJSONArray.getJSONObject(0), 50, 0);
        _assertAttibutes(sourcesJSONArray.getJSONObject(1), 200, 50);
        _assertAttibutes(sourcesJSONArray.getJSONObject(2), 280, 200);
        _assertAttibutes(sourcesJSONArray.getJSONObject(3), 330, 280);
    }
}

From source file:com.liferay.adaptive.media.image.item.selector.internal.resolver.test.FileEntryAdaptiveMediaImageURLItemSelectorReturnTypeResolverTest.java

License:Open Source License

@Test
public void testHDMediaQueryAppliesWhenHeightHas1PXLessThanExpected() throws Exception {

    try (DestinationReplacer destinationReplacer = new DestinationReplacer(
            "liferay/adaptive_media_processor")) {

        ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group,
                TestPropsValues.getUserId());

        final FileEntry fileEntry = _addImageFileEntry(serviceContext);

        _addTestVariant("small", "uuid0", 50, 50);
        _addTestVariant("small.hd", "uuid1", 99, 100);

        String value = _resolver.getValue(fileEntry, null);

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject(value);

        String defaultSource = jsonObject.getString("defaultSource");

        Assert.assertEquals(DLUtil.getPreviewURL(fileEntry, fileEntry.getFileVersion(), null, StringPool.BLANK,
                false, false), defaultSource);

        JSONArray sourcesJSONArray = jsonObject.getJSONArray("sources");

        Assert.assertEquals(2, sourcesJSONArray.length());

        _assertHDSrcSource(sourcesJSONArray.getJSONObject(0), fileEntry.getFileEntryId(), "uuid0", "uuid1",
                fileEntry.getTitle());
        _assertSrcSource(sourcesJSONArray.getJSONObject(1), fileEntry.getFileEntryId(), "uuid1",
                fileEntry.getTitle());//  www  .jav a  2  s  .c om

        _assertAttibutes(sourcesJSONArray.getJSONObject(0), 50, 0);
        _assertAttibutes(sourcesJSONArray.getJSONObject(1), 100, 50);
    }
}

From source file:com.liferay.adaptive.media.image.item.selector.internal.resolver.test.FileEntryAdaptiveMediaImageURLItemSelectorReturnTypeResolverTest.java

License:Open Source License

@Test
public void testHDMediaQueryAppliesWhenHeightHas1PXMoreThanExpected() throws Exception {

    try (DestinationReplacer destinationReplacer = new DestinationReplacer(
            "liferay/adaptive_media_processor")) {

        _addTestVariant("small", "uuid0", 50, 50);
        _addTestVariant("small.hd", "uuid1", 101, 100);

        ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group,
                TestPropsValues.getUserId());

        final FileEntry fileEntry = _addImageFileEntry(serviceContext);

        String value = _resolver.getValue(fileEntry, null);

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject(value);

        String defaultSource = jsonObject.getString("defaultSource");

        Assert.assertEquals(DLUtil.getPreviewURL(fileEntry, fileEntry.getFileVersion(), null, StringPool.BLANK,
                false, false), defaultSource);

        JSONArray sourcesJSONArray = jsonObject.getJSONArray("sources");

        Assert.assertEquals(2, sourcesJSONArray.length());

        _assertHDSrcSource(sourcesJSONArray.getJSONObject(0), fileEntry.getFileEntryId(), "uuid0", "uuid1",
                fileEntry.getTitle());
        _assertSrcSource(sourcesJSONArray.getJSONObject(1), fileEntry.getFileEntryId(), "uuid1",
                fileEntry.getTitle());//  www.ja v  a  2s . co  m

        _assertAttibutes(sourcesJSONArray.getJSONObject(0), 50, 0);
        _assertAttibutes(sourcesJSONArray.getJSONObject(1), 100, 50);
    }
}

From source file:com.liferay.adaptive.media.image.item.selector.internal.resolver.test.FileEntryAdaptiveMediaImageURLItemSelectorReturnTypeResolverTest.java

License:Open Source License

@Test
public void testHDMediaQueryAppliesWhenWidthHas1PXLessThanExpected() throws Exception {

    try (DestinationReplacer destinationReplacer = new DestinationReplacer(
            "liferay/adaptive_media_processor")) {

        _addTestVariant("small", "uuid0", 50, 50);
        _addTestVariant("small.hd", "uuid1", 100, 99);

        ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group,
                TestPropsValues.getUserId());

        final FileEntry fileEntry = _addImageFileEntry(serviceContext);

        String value = _resolver.getValue(fileEntry, null);

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject(value);

        String defaultSource = jsonObject.getString("defaultSource");

        Assert.assertEquals(DLUtil.getPreviewURL(fileEntry, fileEntry.getFileVersion(), null, StringPool.BLANK,
                false, false), defaultSource);

        JSONArray sourcesJSONArray = jsonObject.getJSONArray("sources");

        Assert.assertEquals(2, sourcesJSONArray.length());

        _assertHDSrcSource(sourcesJSONArray.getJSONObject(0), fileEntry.getFileEntryId(), "uuid0", "uuid1",
                fileEntry.getTitle());
        _assertSrcSource(sourcesJSONArray.getJSONObject(1), fileEntry.getFileEntryId(), "uuid1",
                fileEntry.getTitle());//from ww w .j av  a  2s  .c o  m

        _assertAttibutes(sourcesJSONArray.getJSONObject(0), 50, 0);
        _assertAttibutes(sourcesJSONArray.getJSONObject(1), 99, 50);
    }
}

From source file:com.liferay.adaptive.media.image.item.selector.internal.resolver.test.FileEntryAdaptiveMediaImageURLItemSelectorReturnTypeResolverTest.java

License:Open Source License

@Test
public void testHDMediaQueryAppliesWhenWidthHas1PXMoreThanExpected() throws Exception {

    try (DestinationReplacer destinationReplacer = new DestinationReplacer(
            "liferay/adaptive_media_processor")) {

        ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group,
                TestPropsValues.getUserId());

        final FileEntry fileEntry = _addImageFileEntry(serviceContext);

        _addTestVariant("small", "uuid0", 50, 50);
        _addTestVariant("small.hd", "uuid1", 100, 101);

        String value = _resolver.getValue(fileEntry, null);

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject(value);

        String defaultSource = jsonObject.getString("defaultSource");

        Assert.assertEquals(DLUtil.getPreviewURL(fileEntry, fileEntry.getFileVersion(), null, StringPool.BLANK,
                false, false), defaultSource);

        JSONArray sourcesJSONArray = jsonObject.getJSONArray("sources");

        Assert.assertEquals(2, sourcesJSONArray.length());

        _assertHDSrcSource(sourcesJSONArray.getJSONObject(0), fileEntry.getFileEntryId(), "uuid0", "uuid1",
                fileEntry.getTitle());
        _assertSrcSource(sourcesJSONArray.getJSONObject(1), fileEntry.getFileEntryId(), "uuid1",
                fileEntry.getTitle());/* w  w w  . j  av  a 2 s  . c o m*/

        _assertAttibutes(sourcesJSONArray.getJSONObject(0), 50, 0);
        _assertAttibutes(sourcesJSONArray.getJSONObject(1), 101, 50);
    }
}

From source file:com.liferay.adaptive.media.image.item.selector.internal.resolver.test.FileEntryAdaptiveMediaImageURLItemSelectorReturnTypeResolverTest.java

License:Open Source License

@Test
public void testHDMediaQueryNotAppliesWhenHeightHas2PXLessThanExpected() throws Exception {

    try (DestinationReplacer destinationReplacer = new DestinationReplacer(
            "liferay/adaptive_media_processor")) {

        ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group,
                TestPropsValues.getUserId());

        final FileEntry fileEntry = _addImageFileEntry(serviceContext);

        _addTestVariant("small", "uuid0", 50, 50);
        _addTestVariant("small.hd", "uuid1", 98, 200);

        String value = _resolver.getValue(fileEntry, null);

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject(value);

        String defaultSource = jsonObject.getString("defaultSource");

        Assert.assertEquals(DLUtil.getPreviewURL(fileEntry, fileEntry.getFileVersion(), null, StringPool.BLANK,
                false, false), defaultSource);

        JSONArray sourcesJSONArray = jsonObject.getJSONArray("sources");

        Assert.assertEquals(2, sourcesJSONArray.length());

        _assertSrcSource(sourcesJSONArray.getJSONObject(0), fileEntry.getFileEntryId(), "uuid0",
                fileEntry.getTitle());
        _assertSrcSource(sourcesJSONArray.getJSONObject(1), fileEntry.getFileEntryId(), "uuid1",
                fileEntry.getTitle());//from w w w  . j  av  a2  s.co  m

        _assertAttibutes(sourcesJSONArray.getJSONObject(0), 50, 0);
        _assertAttibutes(sourcesJSONArray.getJSONObject(1), 200, 50);
    }
}