package com.ese.ils.beta.beans; import java.io.Serializable; import java.io.UnsupportedEncodingException; import java.net.InetAddress; import java.net.URLEncoder; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; import javax.faces.bean.ManagedBean; import javax.faces.bean.ManagedProperty; import javax.faces.bean.SessionScoped; import javax.faces.bean.ViewScoped; import javax.faces.event.ActionEvent; import javax.faces.model.SelectItem; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.exception.SystemException; import com.liferay.portal.kernel.repository.model.FileEntry; import com.liferay.portal.kernel.repository.model.Folder; import com.liferay.portal.util.PortalUtil; import com.liferay.portlet.bookmarks.NoSuchFolderException; import com.liferay.portlet.documentlibrary.model.DLFileEntry; import com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil; import com.liferay.portlet.documentlibrary.service.DLAppServiceUtil; import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil; /** * behandelt Gruppenfunktionen und Navigation bei Gruppenfunktionalitaet * @author julien hofer * */ @ManagedBean @ViewScoped public class DozentGroupBackingBean implements Serializable { private static final long serialVersionUID = 6227101302887655646L; @ManagedProperty(value="#{dozentNavigationBean}") private transient DozentNavigationBean dozentNavigationBean; @ManagedProperty(value="#{dozentGroupNavigationBean}") private transient DozentGroupNavigationBean dozentGroupNavigationBean; @ManagedProperty(value="#{dozentVoteNavigationBean}") private transient DozentVoteNavigationBean dozentVoteNavigationBean; @ManagedProperty(value="#{dozentGroupData}") private transient DozentGroupData dozentGroupData; //Variablen private static final long repositoryId = 25509; //TODO repositoryId dynamische machen !!! private String sessionPassword; private List<SelectItem> dozentContentItems; private String contentUrl; private String currentContentId; private String sessionId; private String uploadedBy; Folder dozentGroupFolder; /** * baut Auswahlliste f�r Gruppeninhalte */ public void fetchContentItems() { System.out.println("fetching Content Items..."); try{ dozentContentItems = new ArrayList<SelectItem>(); System.out.println("getting Group Parent Folder..."); Folder dozentGroupParentFolder = DLAppServiceUtil.getFolder(repositoryId, 0, "group"); System.out.println("getting Group Folder..."); dozentGroupFolder = DLAppServiceUtil.getFolder(repositoryId, dozentGroupParentFolder.getFolderId(), "" + sessionId); System.out.println("filling SelectList with Items..."); System.out.println("Dozent Group Folder Id " + dozentGroupFolder.getFolderId()); List<FileEntry> testEntry = DLAppServiceUtil.getFileEntries(repositoryId, dozentGroupFolder.getFolderId()); System.out.println("Test Entry Size = " + testEntry.size()); for (FileEntry fileEntry: DLAppServiceUtil.getFileEntries(repositoryId, dozentGroupFolder.getFolderId())) { dozentContentItems.add(new SelectItem(fileEntry.getFileEntryId(),fileEntry.getTitle())); } } catch (SystemException e) { System.out.println("SYSTEM EXCEPTION!!!"); e.printStackTrace(); } catch (NoSuchFolderException e) { System.out.println("No Folder exsist... ->" + e.getMessage()); } catch (PortalException e) { System.out.println(e.getMessage()); } } /** * holt Inhalt einer Gruppe anhand der <code>contentId</code> * @param contentId */ public void fetchContent(long contentId) { System.out.println("fetching content..."); String prefix; try{ prefix = PortalUtil.getPortalURL(InetAddress.getLocalHost().getHostAddress(), PortalUtil.getPortalPort(), false); DLFileEntry entry = DLFileEntryLocalServiceUtil.getDLFileEntry(contentId); setUploadedBy(entry.getUserName()); contentUrl = (prefix + "/documents/" +entry.getGroupId() + "/" + entry.getFolderId() + "/" + URLEncoder.encode(entry.getTitle(), "utf-8")); System.out.println(contentUrl); } catch (SystemException sysEx) { System.out.println("SystemException!!!"); sysEx.printStackTrace(); } catch (UnknownHostException e) { System.out.println("The host is unknown!"); e.printStackTrace(); } catch (UnsupportedEncodingException e) { System.out.println("The encoding failed!"); e.printStackTrace(); } catch (PortalException e) { System.out.println("Portal Exception!!!"); e.printStackTrace(); } } /** * beitritt zu einer Gruppe mit <code>sessionId</code> * @param event * @param sessionId */ public void sessionLogin(ActionEvent event, long sessionId) { System.out.println("Session Login..."); long tmp = sessionId + 1337; System.out.println("Login mit ID: " + sessionId); System.out.println("Password: " + tmp); if (sessionPassword.equals(""+tmp)){ moveToDozentGroupContentSelection(event); } } /** * navigiert zur Auswahl von Gruppeninhalten * @param event */ public void moveToDozentGroupContentSelection(ActionEvent event) { sessionId = String.valueOf(dozentGroupData.getCurrentGroupId()); fetchContentItems(); dozentVoteNavigationBean.setDozentCreateVoteStatus(false); dozentVoteNavigationBean.setDozentEditVoteStatus(false); dozentVoteNavigationBean.setDozentResultsStatus(false); dozentVoteNavigationBean.setDozentShowVoteStatus(false); dozentVoteNavigationBean.setDozentVoteHomeStatus(false); dozentVoteNavigationBean.setDozentShowVoteStatus(false); dozentNavigationBean.setDozentShowFavoritesStatus(false); dozentNavigationBean.setDozentShowGroupStatus(false); dozentGroupNavigationBean.setDozentGroupShowContentStatus(false); dozentGroupNavigationBean.setDozentGroupContentSelectionStatus(true); } /** * navigiert zum Anzeigen eines bestimmten Inhalts einer Gruppe * anhand der <code>currentContentId</code> * @param event */ public void moveToDozentShowGroupContent(ActionEvent event) { System.out.println("fetching selected content..."); fetchContent(Long.valueOf(currentContentId)); dozentNavigationBean.setDozentShowGroupStatus(false); dozentNavigationBean.setDozentShowFavoritesStatus(false); dozentVoteNavigationBean.setDozentCreateVoteStatus(false); dozentVoteNavigationBean.setDozentEditVoteStatus(false); dozentVoteNavigationBean.setDozentResultsStatus(false); dozentVoteNavigationBean.setDozentShowVoteStatus(false); dozentVoteNavigationBean.setDozentVoteHomeStatus(false); dozentVoteNavigationBean.setDozentShowVoteStatus(false); dozentGroupNavigationBean.setDozentGroupShowContentStatus(true); dozentGroupNavigationBean.setDozentGroupContentSelectionStatus(false); } //GETTER UND SETTER public List<SelectItem> getDozentContentItems() { return dozentContentItems; } public void setDozentContentItems(List<SelectItem> dozentContentItems) { this.dozentContentItems = dozentContentItems; } public String getContentUrl() { return contentUrl; } public void setContentUrl(String contentUrl) { this.contentUrl = contentUrl; } public String getSessionId() { return sessionId; } public void setSessionId(String sessionId) { this.sessionId = sessionId; } public String getCurrentContentId() { return currentContentId; } public void setCurrentContentId(String currentContentId) { this.currentContentId = currentContentId; } public DozentGroupNavigationBean getDozentGroupNavigationBean() { return dozentGroupNavigationBean; } public void setDozentGroupNavigationBean( DozentGroupNavigationBean dozentGroupNavigationBean) { this.dozentGroupNavigationBean = dozentGroupNavigationBean; } public DozentNavigationBean getDozentNavigationBean() { return dozentNavigationBean; } public void setDozentNavigationBean(DozentNavigationBean dozentNavigationBean) { this.dozentNavigationBean = dozentNavigationBean; } public DozentGroupData getDozentGroupData() { return dozentGroupData; } public void setDozentGroupData(DozentGroupData dozentGroupData) { this.dozentGroupData = dozentGroupData; } public DozentVoteNavigationBean getDozentVoteNavigationBean() { return dozentVoteNavigationBean; } public void setDozentVoteNavigationBean( DozentVoteNavigationBean dozentVoteNavigationBean) { this.dozentVoteNavigationBean = dozentVoteNavigationBean; } public String getUploadedBy() { return uploadedBy; } public void setUploadedBy(String uploadedBy) { this.uploadedBy = uploadedBy; } }