protected FileEntry updateFileEntry( long fileEntryId, String sourceFileName, String title, boolean majorVersion) throws Exception { String description = StringPool.BLANK; String changeLog = StringPool.BLANK; byte[] bytes = null; if (Validator.isNotNull(sourceFileName)) { bytes = CONTENT.getBytes(); } ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); return DLAppServiceUtil.updateFileEntry( fileEntryId, sourceFileName, ContentTypes.TEXT_PLAIN, title, description, changeLog, majorVersion, bytes, serviceContext); }
protected FileEntry addFileEntry( long folderId, String sourceFileName, String title, byte[] bytes, int workflowAction) throws Exception { String description = StringPool.BLANK; String changeLog = StringPool.BLANK; if ((bytes == null) && Validator.isNotNull(sourceFileName)) { bytes = CONTENT.getBytes(); } ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); serviceContext.setWorkflowAction(workflowAction); return DLAppServiceUtil.addFileEntry( TestPropsValues.getGroupId(), folderId, sourceFileName, ContentTypes.TEXT_PLAIN, title, description, changeLog, bytes, serviceContext); }
public void fromJson(JSONObject jsonObject) throws JSONException { if (null == jsonObject) { return; } JSONArray subItemArray; CONTENT content = new CONTENT(); content.fromJson(jsonObject.optJSONObject("content")); this.content = content; this.uid = jsonObject.optInt("uid"); this.sid = jsonObject.optString("sid"); this.ver = jsonObject.optInt("ver"); return; }
@Test public void testWithoutExtensionWithContent() throws Exception { testVersionUpdate( _BASE_FILE_NAME, _ZERO_BYTES, ContentTypes.APPLICATION_OCTET_STREAM, _BASE_FILE_NAME, CONTENT.getBytes(), ContentTypes.TEXT_PLAIN); }
@Test public void testWithExtensionWithContent() throws Exception { testVersionUpdate( _FULL_FILE_NAME, _ZERO_BYTES, ContentTypes.TEXT_PLAIN, _FULL_FILE_NAME, CONTENT.getBytes(), ContentTypes.TEXT_PLAIN); }
public JSONObject toJson() throws JSONException { JSONObject localItemObject = new JSONObject(); JSONArray itemJSONArray = new JSONArray(); if (null != content) { localItemObject.put("content", content.toJson()); } localItemObject.put("uid", uid); localItemObject.put("sid", sid); localItemObject.put("ver", ver); return localItemObject; }
@Test public void testAddFileEntryWithInvalidMimeType() throws Exception { long folderId = parentFolder.getFolderId(); String description = StringPool.BLANK; String changeLog = StringPool.BLANK; ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); serviceContext.setScopeGroupId(group.getGroupId()); try { String name = "InvalidMime.txt"; byte[] bytes = CONTENT.getBytes(); FileEntry fileEntry = DLAppServiceUtil.addFileEntry( group.getGroupId(), folderId, name, ContentTypes.APPLICATION_OCTET_STREAM, name, description, changeLog, bytes, serviceContext); Assert.assertEquals(ContentTypes.TEXT_PLAIN, fileEntry.getMimeType()); name = "InvalidMime"; fileEntry = DLAppServiceUtil.updateFileEntry( fileEntry.getFileEntryId(), name, null, name, description, changeLog, true, bytes, serviceContext); Assert.assertEquals(ContentTypes.TEXT_PLAIN, fileEntry.getMimeType()); } catch (Exception e) { Assert.fail("Unable to add file with invalid mime type " + StackTraceUtil.getStackTrace(e)); } }
@Override protected void doRun() throws Exception { try { FileEntry fileEntry = DLAppServiceUtil.getFileEntry(_fileEntryIds[_index]); InputStream is = fileEntry.getContentStream(); String content = StringUtil.read(is); if (CONTENT.equals(content)) { _log.debug("Retrieved file " + _index); _success = true; } } catch (Exception e) { _log.error("Unable to add file " + _index, e); } }
@Test public void testAsstTags() throws Exception { long folderId = parentFolder.getFolderId(); String name = "TestTags.txt"; String description = StringPool.BLANK; String changeLog = StringPool.BLANK; byte[] bytes = CONTENT.getBytes(); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); serviceContext.setScopeGroupId(group.getGroupId()); String[] assetTagNames = new String[] {"hello", "world"}; serviceContext.setAssetTagNames(assetTagNames); FileEntry fileEntry = DLAppServiceUtil.addFileEntry( group.getGroupId(), folderId, name, ContentTypes.TEXT_PLAIN, name, description, changeLog, bytes, serviceContext); AssetEntry assetEntry = AssetEntryLocalServiceUtil.fetchEntry( DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId()); AssertUtils.assertEqualsSorted(assetTagNames, assetEntry.getTagNames()); Thread.sleep(1000 * TestPropsValues.JUNIT_DELAY_FACTOR); _fileEntry = fileEntry; search(_fileEntry, false, "hello", true); search(_fileEntry, false, "world", true); search(_fileEntry, false, "liferay", false); assetTagNames = new String[] {"hello", "world", "liferay"}; serviceContext.setAssetTagNames(assetTagNames); fileEntry = DLAppServiceUtil.updateFileEntry( fileEntry.getFileEntryId(), name, ContentTypes.TEXT_PLAIN, name, description, changeLog, false, bytes, serviceContext); assetEntry = AssetEntryLocalServiceUtil.fetchEntry( DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId()); AssertUtils.assertEqualsSorted(assetTagNames, assetEntry.getTagNames()); Thread.sleep(1000 * TestPropsValues.JUNIT_DELAY_FACTOR); _fileEntry = fileEntry; search(_fileEntry, false, "hello", true); search(_fileEntry, false, "world", true); search(_fileEntry, false, "liferay", true); DLAppServiceUtil.deleteFileEntry(_fileEntry.getFileEntryId()); _fileEntry = null; }
@Test public void testAddNullFileEntry() throws Exception { long folderId = parentFolder.getFolderId(); String description = StringPool.BLANK; String changeLog = StringPool.BLANK; ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); serviceContext.setScopeGroupId(group.getGroupId()); try { String name = "Bytes-null.txt"; byte[] bytes = null; FileEntry fileEntry = DLAppServiceUtil.addFileEntry( group.getGroupId(), folderId, name, ContentTypes.TEXT_PLAIN, name, description, changeLog, bytes, serviceContext); DLAppServiceUtil.updateFileEntry( fileEntry.getFileEntryId(), name, ContentTypes.TEXT_PLAIN, name, description, changeLog, true, bytes, serviceContext); String newName = "Bytes-changed.txt"; bytes = CONTENT.getBytes(); DLAppServiceUtil.updateFileEntry( fileEntry.getFileEntryId(), newName, ContentTypes.TEXT_PLAIN, newName, description, changeLog, true, bytes, serviceContext); } catch (Exception e) { Assert.fail("Unable to pass null byte[] " + StackTraceUtil.getStackTrace(e)); } try { String name = "File-null.txt"; File file = null; FileEntry fileEntry = DLAppServiceUtil.addFileEntry( group.getGroupId(), folderId, name, ContentTypes.TEXT_PLAIN, name, description, changeLog, file, serviceContext); DLAppServiceUtil.updateFileEntry( fileEntry.getFileEntryId(), name, ContentTypes.TEXT_PLAIN, name, description, changeLog, true, file, serviceContext); try { String newName = "File-changed.txt"; file = FileUtil.createTempFile(CONTENT.getBytes()); DLAppServiceUtil.updateFileEntry( fileEntry.getFileEntryId(), newName, ContentTypes.TEXT_PLAIN, newName, description, changeLog, true, file, serviceContext); } finally { FileUtil.delete(file); } } catch (Exception e) { Assert.fail("Unable to pass null File " + StackTraceUtil.getStackTrace(e)); } try { String name = "IS-null.txt"; InputStream is = null; FileEntry fileEntry = DLAppServiceUtil.addFileEntry( group.getGroupId(), folderId, name, ContentTypes.TEXT_PLAIN, name, description, changeLog, is, 0, serviceContext); DLAppServiceUtil.updateFileEntry( fileEntry.getFileEntryId(), name, ContentTypes.TEXT_PLAIN, name, description, changeLog, true, is, 0, serviceContext); try { String newName = "IS-changed.txt"; is = new ByteArrayInputStream(CONTENT.getBytes()); DLAppServiceUtil.updateFileEntry( fileEntry.getFileEntryId(), newName, ContentTypes.TEXT_PLAIN, newName, description, changeLog, true, is, 0, serviceContext); } finally { if (is != null) { is.close(); } } } catch (Exception e) { Assert.fail("Unable to pass null InputStream " + StackTraceUtil.getStackTrace(e)); } }