public void testFindByPrimaryKeyExisting() throws Exception { IGFolder newIGFolder = addIGFolder(); IGFolder existingIGFolder = _persistence.findByPrimaryKey(newIGFolder.getPrimaryKey()); assertEquals(existingIGFolder, newIGFolder); }
protected long getFolderId(long companyId, String[] pathArray, boolean parent) throws Exception { long folderId = IGFolderConstants.DEFAULT_PARENT_FOLDER_ID; if (pathArray.length <= 1) { return folderId; } else { long groupId = WebDAVUtil.getGroupId(companyId, pathArray); int x = pathArray.length; if (parent) { x--; } for (int i = 2; i < x; i++) { String name = pathArray[i]; IGFolder folder = IGFolderServiceUtil.getFolder(groupId, folderId, name); if (groupId == folder.getGroupId()) { folderId = folder.getFolderId(); } } } return folderId; }
public int deleteResource(WebDAVRequest webDavRequest) throws WebDAVException { try { Resource resource = getResource(webDavRequest); if (resource == null) { return HttpServletResponse.SC_NOT_FOUND; } Object model = resource.getModel(); if (model instanceof IGFolder) { IGFolder folder = (IGFolder) model; IGFolderServiceUtil.deleteFolder(folder.getFolderId()); } else { IGImage image = (IGImage) model; IGImageServiceUtil.deleteImage(image.getImageId()); } return HttpServletResponse.SC_NO_CONTENT; } catch (PrincipalException pe) { return HttpServletResponse.SC_FORBIDDEN; } catch (Exception e) { throw new WebDAVException(e); } }
public int copyCollectionResource( WebDAVRequest webDavRequest, Resource resource, String destination, boolean overwrite, long depth) throws WebDAVException { try { String[] destinationArray = WebDAVUtil.getPathArray(destination, true); long companyId = webDavRequest.getCompanyId(); long parentFolderId = IGFolderConstants.DEFAULT_PARENT_FOLDER_ID; try { parentFolderId = getParentFolderId(companyId, destinationArray); } catch (NoSuchFolderException nsfe) { return HttpServletResponse.SC_CONFLICT; } IGFolder folder = (IGFolder) resource.getModel(); long groupId = WebDAVUtil.getGroupId(companyId, destination); String name = WebDAVUtil.getResourceName(destinationArray); String description = folder.getDescription(); int status = HttpServletResponse.SC_CREATED; if (overwrite) { if (deleteResource(groupId, parentFolderId, name)) { status = HttpServletResponse.SC_NO_CONTENT; } } ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddCommunityPermissions(isAddCommunityPermissions(groupId)); serviceContext.setAddGuestPermissions(true); serviceContext.setScopeGroupId(groupId); if (depth == 0) { IGFolderServiceUtil.addFolder(parentFolderId, name, description, serviceContext); } else { IGFolderServiceUtil.copyFolder( folder.getFolderId(), parentFolderId, name, description, serviceContext); } return status; } catch (DuplicateFolderNameException dfne) { return HttpServletResponse.SC_PRECONDITION_FAILED; } catch (PrincipalException pe) { return HttpServletResponse.SC_FORBIDDEN; } catch (Exception e) { throw new WebDAVException(e); } }
public void testRemove() throws Exception { IGFolder newIGFolder = addIGFolder(); _persistence.remove(newIGFolder); IGFolder existingIGFolder = _persistence.fetchByPrimaryKey(newIGFolder.getPrimaryKey()); assertNull(existingIGFolder); }
public void testCreate() throws Exception { long pk = nextLong(); IGFolder igFolder = _persistence.create(pk); assertNotNull(igFolder); assertEquals(igFolder.getPrimaryKey(), pk); }
public void processAction( ActionMapping mapping, ActionForm form, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest); String fileLogoParam = "file"; File file = uploadRequest.getFile(fileLogoParam); ServiceContext sc; try { sc = ServiceContextFactory.getInstance(this.getClass().getName(), actionRequest); // Make sure the uploaded images can be view by any one; sc.setAddCommunityPermissions(true); sc.setAddGuestPermissions(true); IGFolder folder = Functions.getIGFolder(sc); // String fileName = uploadRequest.getFileName(fileLogoParam); String contentType = uploadRequest.getContentType(fileLogoParam); IGImage image = IGImageLocalServiceUtil.addImage( sc.getUserId(), folder.getFolderId(), file.getName() + (new Time()).toString(), file.getName(), file, contentType, sc); HttpServletRequest servletRequest = PortalUtil.getHttpServletRequest(actionRequest); String res = image.getImageId() + "|" + ProGateUtil.getImageURL(image.getSmallImageId(), servletRequest) + "|" + ProGateUtil.getImageURL(image.getLargeImageId(), servletRequest); ProGateUtil.servletPrint(actionResponse, res); } catch (PortalException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SystemException se) { se.printStackTrace(); } catch (NullPointerException e2) { e2.printStackTrace(); } }
public void testDynamicQueryByPrimaryKeyExisting() throws Exception { IGFolder newIGFolder = addIGFolder(); DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(IGFolder.class, IGFolder.class.getClassLoader()); dynamicQuery.add(RestrictionsFactoryUtil.eq("folderId", newIGFolder.getFolderId())); List<IGFolder> result = _persistence.findWithDynamicQuery(dynamicQuery); assertEquals(1, result.size()); IGFolder existingIGFolder = result.get(0); assertEquals(existingIGFolder, newIGFolder); }
protected Resource toResource(WebDAVRequest webDavRequest, IGFolder folder, boolean appendPath) { String parentPath = getRootPath() + webDavRequest.getPath(); String name = StringPool.BLANK; if (appendPath) { name = folder.getName(); } Resource resource = new BaseResourceImpl( parentPath, name, folder.getName(), folder.getCreateDate(), folder.getModifiedDate()); resource.setModel(folder); resource.setClassName(IGFolder.class.getName()); resource.setPrimaryKey(folder.getPrimaryKey()); return resource; }
public Resource getResource(WebDAVRequest webDavRequest) throws WebDAVException { try { String[] pathArray = webDavRequest.getPathArray(); long companyId = webDavRequest.getCompanyId(); long parentFolderId = getParentFolderId(companyId, pathArray); String name = WebDAVUtil.getResourceName(pathArray); if (Validator.isNull(name)) { String path = getRootPath() + webDavRequest.getPath(); return new BaseResourceImpl(path, StringPool.BLANK, getToken()); } try { IGFolder folder = IGFolderServiceUtil.getFolder(webDavRequest.getGroupId(), parentFolderId, name); if ((folder.getParentFolderId() != parentFolderId) || (webDavRequest.getGroupId() != folder.getGroupId())) { throw new NoSuchFolderException(); } return toResource(webDavRequest, folder, false); } catch (NoSuchFolderException nsfe) { try { long groupId = webDavRequest.getGroupId(); IGImage image = IGImageServiceUtil.getImageByFolderIdAndNameWithExtension( groupId, parentFolderId, name); return toResource(webDavRequest, image, false); } catch (NoSuchImageException nsie) { return null; } } } catch (Exception e) { throw new WebDAVException(e); } }
protected IGFolder addIGFolder() throws Exception { long pk = nextLong(); IGFolder igFolder = _persistence.create(pk); igFolder.setUuid(randomString()); igFolder.setGroupId(nextLong()); igFolder.setCompanyId(nextLong()); igFolder.setUserId(nextLong()); igFolder.setCreateDate(nextDate()); igFolder.setModifiedDate(nextDate()); igFolder.setParentFolderId(nextLong()); igFolder.setName(randomString()); igFolder.setDescription(randomString()); _persistence.update(igFolder, false); return igFolder; }
public int moveCollectionResource( WebDAVRequest webDavRequest, Resource resource, String destination, boolean overwrite) throws WebDAVException { try { String[] destinationArray = WebDAVUtil.getPathArray(destination, true); IGFolder folder = (IGFolder) resource.getModel(); long companyId = webDavRequest.getCompanyId(); long groupId = WebDAVUtil.getGroupId(companyId, destinationArray); long folderId = folder.getFolderId(); long parentFolderId = getParentFolderId(companyId, destinationArray); String name = WebDAVUtil.getResourceName(destinationArray); String description = folder.getDescription(); ServiceContext serviceContext = new ServiceContext(); int status = HttpServletResponse.SC_CREATED; if (overwrite) { if (deleteResource(groupId, parentFolderId, name)) { status = HttpServletResponse.SC_NO_CONTENT; } } IGFolderServiceUtil.updateFolder( folderId, parentFolderId, name, description, false, serviceContext); return status; } catch (PrincipalException pe) { return HttpServletResponse.SC_FORBIDDEN; } catch (DuplicateFolderNameException dfne) { return HttpServletResponse.SC_PRECONDITION_FAILED; } catch (Exception e) { throw new WebDAVException(e); } }
protected boolean deleteResource(long groupId, long parentFolderId, String name) throws PortalException, SystemException { try { IGFolder folder = IGFolderServiceUtil.getFolder(groupId, parentFolderId, name); IGFolderServiceUtil.deleteFolder(folder.getFolderId()); return true; } catch (NoSuchFolderException nsfe) { if (name.indexOf(StringPool.PERIOD) == -1) { return false; } try { IGImageServiceUtil.deleteImageByFolderIdAndNameWithExtension(groupId, parentFolderId, name); return true; } catch (NoSuchImageException nsie) { } } return false; }
public void testUpdateExisting() throws Exception { long pk = nextLong(); IGFolder newIGFolder = _persistence.create(pk); newIGFolder.setUuid(randomString()); newIGFolder.setGroupId(nextLong()); newIGFolder.setCompanyId(nextLong()); newIGFolder.setUserId(nextLong()); newIGFolder.setCreateDate(nextDate()); newIGFolder.setModifiedDate(nextDate()); newIGFolder.setParentFolderId(nextLong()); newIGFolder.setName(randomString()); newIGFolder.setDescription(randomString()); _persistence.update(newIGFolder, false); IGFolder existingIGFolder = _persistence.findByPrimaryKey(newIGFolder.getPrimaryKey()); assertEquals(existingIGFolder.getUuid(), newIGFolder.getUuid()); assertEquals(existingIGFolder.getFolderId(), newIGFolder.getFolderId()); assertEquals(existingIGFolder.getGroupId(), newIGFolder.getGroupId()); assertEquals(existingIGFolder.getCompanyId(), newIGFolder.getCompanyId()); assertEquals(existingIGFolder.getUserId(), newIGFolder.getUserId()); assertEquals( Time.getShortTimestamp(existingIGFolder.getCreateDate()), Time.getShortTimestamp(newIGFolder.getCreateDate())); assertEquals( Time.getShortTimestamp(existingIGFolder.getModifiedDate()), Time.getShortTimestamp(newIGFolder.getModifiedDate())); assertEquals(existingIGFolder.getParentFolderId(), newIGFolder.getParentFolderId()); assertEquals(existingIGFolder.getName(), newIGFolder.getName()); assertEquals(existingIGFolder.getDescription(), newIGFolder.getDescription()); }