Example usage for com.liferay.portal.kernel.repository.model Folder getFolderId

List of usage examples for com.liferay.portal.kernel.repository.model Folder getFolderId

Introduction

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

Prototype

public long getFolderId();

Source Link

Usage

From source file:org.politaktiv.map.app.PolitaktivMapPortlet.java

License:Apache License

@Override
public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
        throws IOException, PortletException {

    String uploadFolderName = getInitParameter("uploadFolder");

    long repositoryId = DLFolderConstants.getDataRepositoryId(this.getCurrentGroupId(renderRequest),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);

    // TODO:      verschieben oder eigene methode
    ServiceContext serviceContext = new ServiceContext();
    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);
    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long currentCompanyId = this.getCurrentCompanyId(renderRequest);
    long currentGroupId = this.getCurrentGroupId(renderRequest);
    long backgroundId = Long.parseLong(renderRequest.getPreferences().getValue("background_id", "0"));

    Folder pictureFolder;

    try {/*w  w  w. j  av a  2s  .c  o  m*/

        //if no background is set (initial) create a default map background
        //TODO: doInit() anschauen
        if (backgroundId == 0) {
            Background initBackground = repository.createInitialBackground(currentCompanyId, currentGroupId);
            MapViewPreferences mapViewPrefs = factory.generateMapViewPreferences(0, //initial values
                    0, 1, initBackground.getBackgroundId());
            mapViewPrefs.valide();

            PortletPreferences prefs = renderRequest.getPreferences();
            repository.storeMapViewPreferences(mapViewPrefs, prefs);
            backgroundId = initBackground.getBackgroundId();
        }

        //background
        //TODO: in DoView genutzt?
        List<Background> backgroundList = repository.findBackgroundsFromCompanyAndGroupId(currentCompanyId,
                currentGroupId);
        renderRequest.setAttribute("backgroundList", backgroundList);

        //Marker
        List<Marker> backgroundMarkerList = repository.findMarkerByBackgroundId(backgroundId);
        renderRequest.setAttribute("backgroundMarkerList", backgroundMarkerList);

        //Picture
        //TODO: in DoView genutzt?
        List<Picture> backgroundPictureList = repository.findPicureByBackgroundId(backgroundId);
        renderRequest.setAttribute("backgroundPictureList", backgroundPictureList);

        //picture folder
        createFolderIfItDoesNotExistWithName(uploadFolderName, serviceContext, repositoryId);
        pictureFolder = DLAppServiceUtil.getFolder(repositoryId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
                uploadFolderName);
        List<FileEntry> portletFolderFiles = DLAppServiceUtil.getFileEntries(repositoryId,
                pictureFolder.getFolderId());
        renderRequest.setAttribute("portletFolderFiles", portletFolderFiles);
        renderRequest.setAttribute("pictureFolderId", pictureFolder.getFolderId());

        //first picture in folder
        String firstFolderFileUuid;
        if (portletFolderFiles.size() >= 1) {
            firstFolderFileUuid = portletFolderFiles.get(0).getUuid();
        } else {
            firstFolderFileUuid = "0"; //if no picture exists
        }
        renderRequest.setAttribute("firstFolderFileUuid", firstFolderFileUuid);

        super.doView(renderRequest, renderResponse);
    } catch (SystemException e) {
        _log.error(e);
    } catch (PortalException e) {
        _log.error(e);
    }
}

From source file:org.politaktiv.map.app.PolitaktivMapPortlet.java

License:Apache License

@Override
public void doEdit(RenderRequest renderRequest, RenderResponse renderResponse)
        throws PortletException, IOException {

    ServiceContext serviceContext = new ServiceContext();
    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);

    String uploadFolderName = getInitParameter("uploadFolder");
    long currentCompanyId = this.getCurrentCompanyId(renderRequest);
    long currentGroupId = this.getCurrentGroupId(renderRequest);

    long repositoryId = DLFolderConstants.getDataRepositoryId(this.getCurrentGroupId(renderRequest),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);

    Folder pictureFolder;
    try {//from  w  w  w. j a  va2 s.  co m

        //background
        List<Background> backgroundList = repository.findBackgroundsFromCompanyAndGroupId(currentCompanyId,
                currentGroupId);
        renderRequest.setAttribute("backgroundList", backgroundList);

        //picture folder
        createFolderIfItDoesNotExistWithName(uploadFolderName, serviceContext, repositoryId);
        pictureFolder = DLAppServiceUtil.getFolder(repositoryId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
                uploadFolderName);
        List<FileEntry> portletFolderFiles = DLAppServiceUtil.getFileEntries(repositoryId,
                pictureFolder.getFolderId());
        renderRequest.setAttribute("portletFolderFiles", portletFolderFiles);
        renderRequest.setAttribute("pictureFolderId", pictureFolder.getFolderId());

        include(editTemplate, renderRequest, renderResponse);

    } catch (SystemException e) {
        _log.error(e);
    } catch (PortalException e) {
        _log.error(e);
    }

}

From source file:org.politaktiv.map.app.PolitaktivMapPortlet.java

License:Apache License

public void fileUpload(ActionRequest actionRequest, ActionResponse actionResponse)
        throws FileNotFoundException, SystemException, PortalException {

    String uploadFolderName = getInitParameter("uploadFolder");

    UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);
    File theFile = uploadRequest.getFile("form_file");

    String fileName = uploadRequest.getFileName("form_file");
    long fileSize = uploadRequest.getSize("form_file");

    String description = StringPool.BLANK;
    String changeLog = StringPool.BLANK;

    ServiceContext serviceContext = new ServiceContext();
    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);

    long repositoryId = DLFolderConstants.getDataRepositoryId(this.getCurrentGroupId(actionRequest),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
    FileInputStream fis = new FileInputStream(theFile);

    createFolderIfItDoesNotExistWithName(uploadFolderName, serviceContext, repositoryId);

    //get folder//from  w  w  w.  ja v a2  s  .co m
    Folder uploadFolder = DLAppServiceUtil.getFolder(repositoryId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            uploadFolderName);
    long folderId = uploadFolder.getFolderId();

    //add entry

    //TODO validation inside this object?
    DLAppServiceUtil.addFileEntry(repositoryId, folderId, fileName,
            new MimetypesFileTypeMap().getContentType(theFile), //TODO: better lib? does not work
            fileName, description, changeLog, fis, fileSize, serviceContext);
}

From source file:org.xmlportletfactory.olafk.customer.CustomerUpload.java

License:Open Source License

/**
 * Create folders for upload documents from our portlet to DocumentLibrary portlet
 * @param request/*  ww w  .  ja  v a 2s  . c  o  m*/
 * @param userId
 * @param groupId
 * @param portletName
 * @return
 * @throws PortalException
 * @throws SystemException
 */
private long createFolders(ActionRequest request, Long userId, Long groupId, String portletName)
        throws PortalException, SystemException {

    //Search for folder in Document Library
    if (dlFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

        return dlFolderId;
    }

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);

    Repository repository = PortletFileRepositoryUtil.addPortletRepository(groupId, portletName,
            serviceContext);

    Folder folder = PortletFileRepositoryUtil.addPortletFolder(userId, repository.getRepositoryId(),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, DOCUMENTLIBRARY_PORTLETFOLDER, serviceContext);

    dlFolderId = folder.getFolderId();

    return dlFolderId;
}