diff --git a/pom.xml b/pom.xml index efb95a9..1df1d81 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ org.gcube.portlets.widgets workspace-sharing-widget jar - 1.5.1-SNAPSHOT + 1.6.0-SNAPSHOT gCube Workspace Sharing Widget gCube Workspace Sharing Widget allows users to share gCube Workspace items diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/WorkspaceSmartSharingController.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/WorkspaceSmartSharingController.java index 8e69bce..2378215 100644 --- a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/WorkspaceSmartSharingController.java +++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/WorkspaceSmartSharingController.java @@ -1,5 +1,5 @@ /** - * + * */ package org.gcube.portlets.widgets.workspacesharingwidget.client; @@ -20,7 +20,7 @@ import com.google.gwt.core.client.GWT; /** * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @Feb 25, 2014 - * + * */ public class WorkspaceSmartSharingController { @@ -38,24 +38,24 @@ public class WorkspaceSmartSharingController { /** - * + * * @param file - a fake file to display the field name ("filename") into dialog * @param listAlreadySharedContact - list of already shared contacts to show into dialog - * + * * base constructor by default does not retrieve the groups - * + * */ public WorkspaceSmartSharingController(FileModel file, List listAlreadySharedContact) { this(file, listAlreadySharedContact, false, false); } - + /** - * + * * @param file - a fake file to display the field name ("filename") into dialog * @param listAlreadySharedContact - list of already shared contacts to show into dialog * @param readGroupsFromHL - if true, read group names from HL * @param readGroupsFromPortal - if true, read group names from Portal (as VRE) - * + * */ public WorkspaceSmartSharingController(FileModel file, List listAlreadySharedContact, boolean readGroupsFromHL, boolean readGroupsFromPortal) { this.listAlreadySharedContact = listAlreadySharedContact; @@ -67,13 +67,13 @@ public class WorkspaceSmartSharingController { updateSharingDialog(); addListenersSharingDialog(); } - + /** * Example of listeners */ private void addListenersSharingDialog(){ - + smartShare.getButtonById(Dialog.OK).addListener(Events.Select, new Listener() { @Override @@ -81,41 +81,37 @@ public class WorkspaceSmartSharingController { // if(smartShare.isValidForm(true)){ // //THAT'S OK -// +// // smartShare.getSharedListUsers(); //@return the selected contacts (as InfoContactModel) -// +// // smartShare.getSharedListUsersCredential(); //@return tthe selected contacts (as CredentialModel) -// +// // for (InfoContactModel contact : smartShare.getSharedListUsers()) { // System.out.println(contact); // } -// +// // for (CredentialModel credential : smartShare.getSharedListUsersCredential()) { // System.out.println(credential); // } -// +// // } } }); } - + /** - * + * * @param fileModel */ private void updateSharingDialog(){ smartShare.unmask(); smartShare.updateSharingDialog(fileModel, listAlreadySharedContact); -// dialogShareItem.show(); - smartShare.layout(); } - - /** - * + * * @return SmartShare An extension of gxt dialog 2.2.5 */ public SmartShare getSharingDialog() { diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/DialogShareWItem.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/DialogShareWItem.java index b254967..34513e3 100644 --- a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/DialogShareWItem.java +++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/DialogShareWItem.java @@ -35,13 +35,13 @@ import com.google.gwt.user.client.ui.FlexTable; import com.google.gwt.user.client.ui.Label; /** - * + * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @Feb 27, 2014 * */ public class DialogShareWItem extends Dialog { - + private int heightTextArea = 100; private TextField txtName; @@ -56,31 +56,31 @@ public class DialogShareWItem extends Dialog { private boolean showError = false; private boolean readGroupsFromHL; private boolean readGroupsFromPortal; - + /** * By DEFAULT DOESN'T READ GROUPS FROM SERVER */ public DialogShareWItem() { this(false, false); } - + /** - * + * * @param readGroupsFromHL * @param readGroupsFromPortal */ public DialogShareWItem(boolean readGroupsFromHL, boolean readGroupsFromPortal) { this.readGroupsFromHL = readGroupsFromHL; this.readGroupsFromPortal = readGroupsFromPortal; - suggestPanel = new MultiValuePanel(userStore, readGroupsFromHL, readGroupsFromPortal); + suggestPanel = new MultiValuePanel(userStore, readGroupsFromHL, readGroupsFromPortal); initLayout(); } - - + + private List listAlreadyShared = new ArrayList(){ - + /** - * + * */ private static final long serialVersionUID = 1L; @@ -89,41 +89,41 @@ public class DialogShareWItem extends Dialog { */ @Override public boolean contains(Object o) { - + if(o==null) return false; - + InfoContactModel contact = (InfoContactModel) o; for (int i = 0; i < listAlreadyShared.size(); i++){ if (contact.getName().compareTo(listAlreadyShared.get(i).getName())==0) return true; } - + return false; - + }; - + }; - - + + /** * Use to modify a shared folder or share an existing folder * @param fileModel * @param type */ - + public void updateSharingDialog(FileModel fileModel, final boolean shareOnlyOwner, final ACL_TYPE defaultACL){ this.fileToShare = fileModel; - + String heading = "Share workspace"; if(fileModel.isDirectory()) heading+=" folder: "; else heading+= " item: "; - + setHeading(heading+fileModel.getName()); txtName = new TextField(); @@ -132,7 +132,7 @@ public class DialogShareWItem extends Dialog { txtName.setReadOnly(true); txtName.setAutoValidate(true); txtName.setFieldLabel("Folder Name"); - + txtOwner = new TextField(); txtOwner.setAllowBlank(true); txtOwner.setValue(""); @@ -143,7 +143,7 @@ public class DialogShareWItem extends Dialog { textAreaDescription.setFieldLabel("Description"); textAreaDescription.setHeight(heightTextArea); textAreaDescription.setWidth(380); - + textAreaDescription.setValue(fileModel.getDescription()); final LayoutContainer lc = new LayoutContainer(); @@ -162,17 +162,17 @@ public class DialogShareWItem extends Dialog { flexTable.setWidget(1, 0, new Label("Add more")); flexTable.setWidget(1, 1, buttonMultiDrag); - - Label labelDescription = new Label("Description"); + + Label labelDescription = new Label("Description"); flexTable.setWidget(2, 0, labelDescription); flexTable.setWidget(2, 1, textAreaDescription); - + hpPermission = new HorizontalPanel(); hpPermission.setVerticalAlign(VerticalAlignment.MIDDLE); - Label labelProperty = new Label("Permissions"); + Label labelProperty = new Label("Permissions"); hpPermission.add(labelProperty); - + WorkspaceSharingController.rpcWorkspaceSharingService.getACLs(new AsyncCallback>() { @Override @@ -191,35 +191,35 @@ public class DialogShareWItem extends Dialog { } }); - - lc.add(flexTable); + + lc.add(flexTable); if(hpPermission!=null) lc.add(hpPermission); lc.mask(); - + userStore.getListSharedUserByFolderId(fileModel.getIdentifier(), new AsyncCallback>() { - + @Override public void onSuccess(List result) { - + for (InfoContactModel infoContactModel : result) { if(infoContactModel.getName()!=null){ listAlreadyShared.add(infoContactModel); suggestPanel.addRecipient(infoContactModel.getName(),false); } - } - + } + lc.unmask(); } - + @Override public void onFailure(Throwable caught) { lc.unmask(); - + } }); - - + + userStore.getOwner(fileModel.getIdentifier(), new AsyncCallback() { @Override @@ -230,7 +230,7 @@ public class DialogShareWItem extends Dialog { @Override public void onSuccess(InfoContactModel result) { txtOwner.setValue(result.getName()); - + if(shareOnlyOwner){ permissionControl(result.getLogin(), true); } @@ -242,14 +242,14 @@ public class DialogShareWItem extends Dialog { add(txtOwner); add(lc); addListners(); - + if(shareOnlyOwner) enableFormDialog(false); //FORM IS DISABLED BY DEFAULT } private void permissionControl(String owner, boolean showAlert){ GWT.log("Permission control compare between owner: "+owner +" and my login: "+WorkspaceSharingController.getMyLogin()); - + if(WorkspaceSharingController.getMyLogin().compareToIgnoreCase(owner)!=0){ enableFormDialog(false); if(showAlert){ @@ -259,19 +259,19 @@ public class DialogShareWItem extends Dialog { enableFormDialog(true); } } - + /* (non-Javadoc) * @see com.extjs.gxt.ui.client.widget.Window#afterShow() */ @Override protected void afterShow() { super.afterShow(); - + if(showError){ MessageBox.alert("Permission denied", "You have no permissions to change sharing. You are not owner of \""+txtName.getValue()+"\"", null); } } - + private void enableFormDialog(boolean bool){ getButtonById(Dialog.OK).setEnabled(bool); buttonMultiDrag.setEnabled(bool); @@ -279,21 +279,21 @@ public class DialogShareWItem extends Dialog { if(permission!=null) permission.setEnabled(bool); } - + public void setAsError(String message){ enableFormDialog(false); this.add(new Html("

"+message+"

")); this.layout(); } - + /** - * + * * @return */ public FileModel getFileToShare() { return fileToShare; } - + public void initLayout(){ FormLayout layout = new FormLayout(); layout.setLabelWidth(90); @@ -305,7 +305,7 @@ public class DialogShareWItem extends Dialog { setWidth(ConstantsSharing.WIDTH_DIALOG); setHeight(ConstantsSharing.HEIGHT_DIALOG); setResizable(true); - setButtonAlign(HorizontalAlignment.CENTER); + setButtonAlign(HorizontalAlignment.CENTER); setButtons(Dialog.OKCANCEL); } @@ -317,7 +317,7 @@ public class DialogShareWItem extends Dialog { public void addListners(){ - + this.getButtonById(Dialog.CANCEL).addSelectionListener(new SelectionListener() { @Override @@ -325,8 +325,8 @@ public class DialogShareWItem extends Dialog { hide(); } }); - - + + /*this.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener() { @Override @@ -334,91 +334,87 @@ public class DialogShareWItem extends Dialog { if(isValidForm(true)) hide(); } - }); + }); */ - + buttonMultiDrag.addClickHandler(new ClickHandler() { - + @Override public void onClick(ClickEvent event) { final DialogMultiDragContact dialog = new DialogMultiDragContact(true,true); final MultiDragContact multiDrag = dialog.getMultiDrag(); dialog.show(); - + List exclusiveContacts = userStore.getExclusiveContactsFromAllContact(suggestPanel.getSelectedUser()); multiDrag.addSourceContacts(exclusiveContacts); - - + for (InfoContactModel infoContactModel : suggestPanel.getSelectedUser()) { if(!listAlreadyShared.contains(infoContactModel)) multiDrag.addTargetContact(infoContactModel); } - + multiDrag.addAlreadySharedContacts(suggestPanel.getSelectedUser()); - -// multiDrag.addTargetContacts(suggestPanel.getSelectedUser()); - dialog.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener() { @Override public void componentSelected(ButtonEvent ce) { - + initSuggestContacts(); for (InfoContactModel infoContactModel : multiDrag.getTargetListContact()) { suggestPanel.addRecipient(infoContactModel.getName(),true); - } - + } + // for (InfoContactModel infoContactModel : multiDrag.getTargetListContact()) { -// +// // if(!listAlreadySharedContains(infoContactModel)) // suggestPanel.addRecipient(infoContactModel.getName(),true); -// } - +// } + suggestPanel.boxSetFocus(); - + // printSelectedUser(); } }); } }); } - + private boolean listAlreadySharedContains(InfoContactModel contact){ - + if(contact==null) return false; - + for (InfoContactModel ct : listAlreadyShared) { - + if(ct.getLogin().compareTo(contact.getLogin())==0){ - + return true; } - + } - + return false; - + } - + //DEBUG private void printSelectedUser(){ - + System.out.println("SELETECTED USERS: "); for (InfoContactModel contact : suggestPanel.getSelectedUser()) System.out.println(contact); } - + private void initSuggestContacts(){ - + suggestPanel.resetItemSelected(); - + for (InfoContactModel contact : listAlreadyShared) { suggestPanel.addRecipient(contact.getName(), false); } - - + + } public String getName() { @@ -428,35 +424,35 @@ public class DialogShareWItem extends Dialog { public String getDescription() { if(textAreaDescription.getValue()==null) return ""; - + return textAreaDescription.getValue(); } /** - * + * * @param displayAlert * @return */ public boolean isValidForm(boolean displayAlert){ - + if(!txtName.isValid()){ if(displayAlert) MessageBox.alert("Attention", "Name must not be empty", null); txtName.focus(); return false; } - + if(getSharedListUsers().size()==0){ if(displayAlert) MessageBox.alert("Attention", "You must pick at least one user with which share the folder", null); suggestPanel.boxSetFocus(); return false; } - + return true; - + } - + public WorkspaceACL getSelectedACL(){ if(permission!=null) return permission.getSelectedACL(); diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/SmartShare.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/SmartShare.java index ee2fdaa..64099aa 100644 --- a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/SmartShare.java +++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/SmartShare.java @@ -1,5 +1,5 @@ /** - * + * */ package org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing; @@ -26,6 +26,7 @@ import com.extjs.gxt.ui.client.widget.LayoutContainer; import com.extjs.gxt.ui.client.widget.MessageBox; import com.extjs.gxt.ui.client.widget.form.TextField; import com.extjs.gxt.ui.client.widget.layout.FormLayout; +import com.google.gwt.core.client.GWT; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -34,12 +35,13 @@ import com.google.gwt.user.client.ui.FlexTable; import com.google.gwt.user.client.ui.Label; /** + * The Class SmartShare. + * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @Mar 3, 2014 - * */ public class SmartShare extends Dialog implements SmartDialogInterface{ - + private TextField txtName; private FileModel fileToShare = null; private UserStore userStore = new UserStore(); @@ -47,66 +49,59 @@ public class SmartShare extends Dialog implements SmartDialogInterface{ private Button buttonMultiDrag = new Button("Choose Contacts"); private boolean readGroupsFromHL; private boolean readGroupsFromPortal; - + /** - * SmartShare base constructor by default does not retrieve groupss - */ + * SmartShare base constructor by default does not retrieve groupss. + */ public SmartShare() { this(false, false); } - + /** - * + * Instantiates a new smart share. + * * @param readGroupsFromHL - if true read group names from HL * @param readGroupsFromPortal - if true read group names from Portal (as VRE) - * */ public SmartShare(boolean readGroupsFromHL, boolean readGroupsFromPortal) { this.readGroupsFromHL = readGroupsFromHL; this.readGroupsFromPortal = readGroupsFromPortal; - suggestPanel = new MultiValuePanel(userStore, readGroupsFromHL, readGroupsFromPortal); + suggestPanel = new MultiValuePanel(userStore, readGroupsFromHL, readGroupsFromPortal); initLayout(); } - - + private List listAlreadyShared = new ArrayList(){ - - /** - * - */ - private static final long serialVersionUID = 1L; + + private static final long serialVersionUID = -610980920163628336L; /** * Compare Login */ @Override public boolean contains(Object o) { - + if(o==null) return false; - + InfoContactModel contact = (InfoContactModel) o; for (int i = 0; i < listAlreadyShared.size(); i++){ if (contact.getName().compareTo(listAlreadyShared.get(i).getName())==0) return true; } - return false; - }; - - }; - + /** - * Use to modify a shared folder or share an existing folder - * @param fileModel - * @param type + * Use to modify a shared folder or share an existing folder. + * + * @param fileModel the file model + * @param listAlreadySharedContact the list already shared contact */ - + public void updateSharingDialog(FileModel fileModel, List listAlreadySharedContact){ this.fileToShare = fileModel; String heading; @@ -116,7 +111,7 @@ public class SmartShare extends Dialog implements SmartDialogInterface{ heading+=" folder: "; else heading+= " : "; - + setHeading(heading+fileModel.getName()); }else setHeading(SmartConstants.HEADER_TITLE); @@ -126,7 +121,7 @@ public class SmartShare extends Dialog implements SmartDialogInterface{ txtName.setValue(fileModel.getName()); txtName.setReadOnly(true); txtName.setAutoValidate(true); - + if(SmartConstants.ITEM_NAME!=null) txtName.setFieldLabel(SmartConstants.ITEM_NAME); @@ -141,7 +136,7 @@ public class SmartShare extends Dialog implements SmartDialogInterface{ Label labelShareWith = new Label(""); if(SmartConstants.SHARE_WITH_USERS!=null) labelShareWith.setText(SmartConstants.SHARE_WITH_USERS); - + flexTable.setWidget(0, 0, labelShareWith); flexTable.setWidget(0, 1, suggestPanel); @@ -150,58 +145,54 @@ public class SmartShare extends Dialog implements SmartDialogInterface{ Label labelAddMore = new Label(""); if(SmartConstants.ADD_MORE!=null) labelAddMore.setText(SmartConstants.ADD_MORE); - + flexTable.setWidget(1, 0, labelAddMore); flexTable.setWidget(1, 1, buttonMultiDrag); - if(listAlreadySharedContact!=null && listAlreadySharedContact.size()>0){ - + userStore.getInfoContactModelsFromCredential(listAlreadySharedContact, new AsyncCallback>() { - + @Override public void onSuccess(List result) { for (InfoContactModel infoContactModel : result) { - if(infoContactModel.getName()!=null){ - listAlreadyShared.add(infoContactModel); - suggestPanel.addRecipient(infoContactModel.getName(),false); - layout(); - } - } - + String name = infoContactModel.getName()!=null && !infoContactModel.getName().isEmpty()?infoContactModel.getName():infoContactModel.getLogin(); + listAlreadyShared.add(infoContactModel); + suggestPanel.addRecipient(name,false); + layout(); + } lc.unmask(); lc.layout(); layout(); - } - + @Override public void onFailure(Throwable caught) { lc.unmask(); - } }); - } - - lc.add(flexTable); - + + lc.add(flexTable); setFocusWidget(suggestPanel.getBox()); add(txtName); -// add(txtOwner); add(lc); addListeners(); - + } - + /** - * - * @return + * Gets the file to share. + * + * @return the file to share */ public FileModel getFileToShare() { return fileToShare; } - + + /** + * Inits the layout. + */ private void initLayout(){ FormLayout layout = new FormLayout(); layout.setLabelWidth(90); @@ -213,67 +204,78 @@ public class SmartShare extends Dialog implements SmartDialogInterface{ setWidth(ConstantsSharing.WIDTH_DIALOG); setHeight(ConstantsSharing.HEIGHT_DIALOG); setResizable(true); - setButtonAlign(HorizontalAlignment.CENTER); + setButtonAlign(HorizontalAlignment.CENTER); setButtons(Dialog.OKCANCEL); setIcon(Resources.getIconShare()); } /** - * + * Gets the shared list users. + * * @return the selected contacts (as InfoContactModel) */ public List getSharedListUsers() { // printSelectedUser(); - + List contacts = new ArrayList(); - + for (InfoContactModel wsuser : suggestPanel.getSelectedUser()) { CredentialModel credential = getCredentialModelFromInfoContactModel(wsuser); wsuser.setReferenceCredential(credential); contacts.add(wsuser); } - + return contacts; } - + /** - * + * Gets the shared list users credential. + * * @return the selected contacts (as CredentialModel) */ public List getSharedListUsersCredential() { List toReturn = new ArrayList(); - + for (InfoContactModel wsuser : suggestPanel.getSelectedUser()) { CredentialModel credential = wsuser.getReferenceCredential(); - + if(credential==null) credential = new CredentialModel(null, "UNKWNOWN LOGIN", wsuser.isGroup()); - + toReturn.add(credential); } return toReturn; } - + + /** + * Gets the credential model from info contact model. + * + * @param infoContact the info contact + * @return the credential model from info contact model + */ private CredentialModel getCredentialModelFromInfoContactModel(InfoContactModel infoContact){ - + if(infoContact==null) return null; - + if(infoContact.getReferenceCredential()==null){ return new CredentialModel(null, infoContact.getLogin(), infoContact.isGroup()); }else if(infoContact.getReferenceCredential()!=null) return infoContact.getReferenceCredential(); - + return null; - + } + /** + * Adds the listeners. + */ public void addListeners(){ - + this.getButtonById(Dialog.CANCEL).addSelectionListener(new SelectionListener() { @Override @@ -281,8 +283,8 @@ public class SmartShare extends Dialog implements SmartDialogInterface{ hide(); } }); - - + + this.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener() { @Override @@ -290,138 +292,172 @@ public class SmartShare extends Dialog implements SmartDialogInterface{ if(isValidForm(false)) hide(); } - }); - + }); + buttonMultiDrag.addClickHandler(new ClickHandler() { - + @Override public void onClick(ClickEvent event) { final DialogMultiDragContact dialog = new DialogMultiDragContact(true,true); final MultiDragContact multiDrag = dialog.getMultiDrag(); dialog.show(); - + printSelectedUser(); List exclusiveContacts = userStore.getExclusiveContactsFromAllContact(suggestPanel.getSelectedUser()); multiDrag.addSourceContacts(exclusiveContacts); - - + for (InfoContactModel infoContactModel : suggestPanel.getSelectedUser()) { if(!listAlreadyShared.contains(infoContactModel)) multiDrag.addTargetContact(infoContactModel); } - + multiDrag.addAlreadySharedContacts(suggestPanel.getSelectedUser()); - -// multiDrag.addTargetContacts(suggestPanel.getSelectedUser()); - dialog.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener() { @Override public void componentSelected(ButtonEvent ce) { - + initSuggestContacts(); for (InfoContactModel infoContactModel : multiDrag.getTargetListContact()) { suggestPanel.addRecipient(infoContactModel.getName(),true); - } - + } + // for (InfoContactModel infoContactModel : multiDrag.getTargetListContact()) { -// +// // if(!listAlreadySharedContains(infoContactModel)) // suggestPanel.addRecipient(infoContactModel.getName(),true); -// } - +// } + suggestPanel.boxSetFocus(); - -// printSelectedUser(); + + } }); } }); } - + + /** + * List already shared contains. + * + * @param contact the contact + * @return true, if successful + */ private boolean listAlreadySharedContains(InfoContactModel contact){ - + if(contact==null) return false; - + for (InfoContactModel ct : listAlreadyShared) { - + if(ct.getLogin().compareTo(contact.getLogin())==0){ - + return true; } - + } - + return false; - + } - + //DEBUG + /** + * Prints the selected user. + */ private void printSelectedUser(){ - - System.out.println("SELETECTED USERS: "); + + GWT.log("SELETECTED USERS: "); for (InfoContactModel contact : suggestPanel.getSelectedUser()) - System.out.println(contact); + GWT.log(contact.toString()); } - + + /** + * Inits the suggest contacts. + */ private void initSuggestContacts(){ - + suggestPanel.resetItemSelected(); - + for (InfoContactModel contact : listAlreadyShared) { suggestPanel.addRecipient(contact.getName(), false); } - - + + } - + + /** + * Sets the as error. + * + * @param message the new as error + */ public void setAsError(String message){ enableFormDialog(false); this.add(new Html("

"+message+"

")); this.layout(); } - + + /** + * Enable form dialog. + * + * @param bool the bool + */ private void enableFormDialog(boolean bool){ getButtonById(Dialog.OK).setEnabled(bool); buttonMultiDrag.setEnabled(bool); } + /** + * Gets the name. + * + * @return the name + */ public String getName() { return txtName.getValue(); } /** - * + * Checks if is valid form. + * * @param displayAlert in case of error - * @return + * @return true, if is valid form */ public boolean isValidForm(boolean displayAlert){ - + if(!txtName.isValid()){ if(displayAlert) MessageBox.alert("Attention", "Name must not be empty", null); txtName.focus(); return false; } - + if(getSharedListUsers().size()==0){ if(displayAlert) MessageBox.alert("Attention", SmartConstants.ERROR_NO_USER_SELECTED, null); suggestPanel.boxSetFocus(); return false; } - + return true; - + } + /** + * Checks if is read groups from hl. + * + * @return true, if is read groups from hl + */ public boolean isReadGroupsFromHL() { return readGroupsFromHL; } + /** + * Checks if is read groups from portal. + * + * @return true, if is read groups from portal + */ public boolean isReadGroupsFromPortal() { return readGroupsFromPortal; } diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/multisuggest/MultiValuePanel.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/multisuggest/MultiValuePanel.java index bdd5bac..c6bb645 100644 --- a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/multisuggest/MultiValuePanel.java +++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/client/view/sharing/multisuggest/MultiValuePanel.java @@ -25,10 +25,10 @@ import com.google.gwt.user.client.ui.SuggestOracle; import com.google.gwt.user.client.ui.TextBox; /** - * + * The Class MultiValuePanel. + * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @Feb 25, 2014 - * */ public class MultiValuePanel extends Composite { @@ -36,24 +36,27 @@ public class MultiValuePanel extends Composite { private List itemsSelected = new ArrayList(); FlowPanel panel = new FlowPanel(); // private HandlerManager eventBus; - private HashMap users = new HashMap(); + private HashMap users = new HashMap(); //AN HAST FULLNAME - INFOCONTACTMODEL private BulletList listBullet = new BulletList(); private SuggestBox box; - private ContactFetcher userFetch; - private MultiWordSuggestOracle oracle = new MultiWordSuggestOracle(); + private ContactFetcher userFetch; + private MultiWordSuggestOracle oracle = new MultiWordSuggestOracle(); //ORACLE OF FULL NAMES private boolean readGroupsFromHL; private boolean readGroupsFromPortal; /** - * - * @param userFetch the ContactFetcher + * Instantiates a new multi value panel. + * + * @param userFetch the ContactFetcher + * @param readGroupsFromHL the read groups from hl + * @param readGroupsFromPortal the read groups from portal */ public MultiValuePanel(ContactFetcher userFetch, boolean readGroupsFromHL, boolean readGroupsFromPortal) { this.userFetch = userFetch; this.readGroupsFromHL = readGroupsFromHL; this.readGroupsFromPortal = readGroupsFromPortal; initWidget(panel); - panel.setWidth("100%"); + panel.setWidth("100%"); listBullet.setStyleName("multivalue-panel-suggest"); final ListItem item = new ListItem(); final TextBox itemBox = new TextBox(); @@ -69,22 +72,22 @@ public class MultiValuePanel extends Composite { // handle backspace if (event.getNativeKeyCode() == KeyCodes.KEY_BACKSPACE) { if ("".equals(itemBox.getValue().trim())) { - + if(listBullet.getWidgetCount()>2){ ListItem li = (ListItem) listBullet.getWidget(listBullet.getWidgetCount() - 2); - + if(li.getWidget(0) instanceof Paragraph){ Paragraph p = (Paragraph) li.getWidget(0); GWT.log("p "+p.getText() +" is removable : " + p.isRemovable()); - if (itemsSelected.contains(p.getText()) && (p.isRemovable()==true)) { + if (itemsSelected.contains(p.getText()) && p.isRemovable()==true) { itemsSelected.remove(p.getText()); GWT.log("Removing selected item: " + p.getText() + "'"); listBullet.remove(li); } - + itemBox.setFocus(true); } - } + } } } } @@ -99,22 +102,30 @@ public class MultiValuePanel extends Composite { panel.add(listBullet); box.getElement().setId("suggestion_box"); //needed for the focus on click panel.getElement().setAttribute("onclick", "document.getElementById('suggestion_box').focus()"); -// box.setFocus(true); } - + + /** + * Box set focus. + */ public void boxSetFocus(){ box.getElement().focus(); box.setFocus(true); -// panel.getElement().setAttribute("onclick", "document.getElementById('suggestion_box').focus()"); } - + + /** + * Gets the flow panel. + * + * @return the flow panel + */ public FlowPanel getFlowPanel(){ return panel; } + /** - * actually insert the contact in the flow panel - * @param itemBox - * @param list + * actually insert the contact in the flow panel. + * + * @param itemBox the item box + * @param list the list */ private void chosenContactItem(final TextBox itemBox, final BulletList list) { if (itemBox.getValue() != null && !"".equals(itemBox.getValue().trim())) { @@ -142,25 +153,34 @@ public class MultiValuePanel extends Composite { itemBox.setFocus(true); } } + /** - * + * Gets the selected user. + * * @return the selected contacts (user logins e.g. pino.pini) */ public List getSelectedUser() { - if (users == null) + if (users == null) return new ArrayList(); else { List toReturn = new ArrayList(); - - for (String login : itemsSelected) { - InfoContactModel wsuser = users.get(login); +// GWT.log("Selected User: "+itemsSelected); +// GWT.log("users: "+users); + for (String fullName : itemsSelected) { + InfoContactModel wsuser = users.get(fullName); if(wsuser!= null && !toReturn.contains(wsuser)) toReturn.add(wsuser); } return toReturn; } } - + + /** + * Removes the list item. + * + * @param displayItem the display item + * @param list the list + */ private void removeListItem(ListItem displayItem, BulletList list) { GWT.log("Removing: " + displayItem.getWidget(0).getElement().getInnerHTML(), null); itemsSelected.remove(displayItem.getWidget(0).getElement().getInnerHTML()); @@ -168,31 +188,34 @@ public class MultiValuePanel extends Composite { } /** + * Gets the suggestions. * * @return names of possible contacts */ private MultiWordSuggestOracle getSuggestions() { - userFetch.getListContact(contacts, false,readGroupsFromHL,readGroupsFromPortal); - return oracle; } - + + /** + * Update suggestions. + * + * @param result the result + */ public void updateSuggestions(List result) { oracle.clear(); - + for (InfoContactModel wsUser : result) { oracle.add(wsUser.getName()); - + } } - - - private AsyncCallback> contacts = new AsyncCallback>() { + private AsyncCallback> contacts = new AsyncCallback>() { + @Override public void onFailure(Throwable caught) { GWT.log("Error on loading contacts"); @@ -201,43 +224,51 @@ public class MultiValuePanel extends Composite { @Override public void onSuccess(List result) { - users.clear(); - for (InfoContactModel wsUser : result) { - oracle.add(wsUser.getName()); - users.put(wsUser.getName(), wsUser); - } - } - }; + String fullName = wsUser.getName(); + if(users.containsKey(fullName)){ //case of homonimy + fullName = fullName+"_"; + users.put(fullName, wsUser); + }else + users.put(fullName, wsUser); + oracle.add(fullName); + } + } + }; + + /** + * Reset item selected. + */ public void resetItemSelected(){ - + listBullet.clear(); itemsSelected.clear(); ListItem item = new ListItem(); item.add(box); - listBullet.add(item); + listBullet.add(item); } /** - * - * @param contact - * @param displayRemoveItem + * Adds the recipient. + * + * @param fullName the full name + * @param displayRemoveItem the display remove item */ public void addRecipient(String fullName, boolean displayRemoveItem) { - + if (fullName != null) { TextBox itemBox = new TextBox(); itemBox.setText(fullName); itemBox.setValue(fullName); final ListItem displayItem = new ListItem(); - + Paragraph p = new Paragraph(fullName); displayItem.add(p); - + if(displayRemoveItem){ displayItem.setStyleName("multivalue-panel-token-ws"); p.setRemovable(true); @@ -247,15 +278,13 @@ public class MultiValuePanel extends Composite { removeListItem(displayItem, listBullet); } }); - + displayItem.add(span); } else{ displayItem.setStyleName("multivalue-panel-token-ws-notselectable"); p.setRemovable(false); } - - GWT.log("Adding selected wp item '" + itemBox.getValue()); itemsSelected.add(itemBox.getValue()); @@ -265,15 +294,23 @@ public class MultiValuePanel extends Composite { itemBox.setValue(""); itemBox.setFocus(true); } - + } + /** + * Clear list. + */ public void clearList() { listBullet.clear(); } + /** + * Gets the box. + * + * @return the box + */ public SuggestBox getBox() { return box; - + } } diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/GWTWorkspaceSharingBuilder.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/GWTWorkspaceSharingBuilder.java index 03af8a9..87b08f6 100644 --- a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/GWTWorkspaceSharingBuilder.java +++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/GWTWorkspaceSharingBuilder.java @@ -1,5 +1,5 @@ /** - * + * */ package org.gcube.portlets.widgets.workspacesharingwidget.server; @@ -35,9 +35,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** + * The Class GWTWorkspaceSharingBuilder. + * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @Feb 25, 2014 - * */ public class GWTWorkspaceSharingBuilder { @@ -48,9 +49,9 @@ public class GWTWorkspaceSharingBuilder { protected static HashMap hashTestUser = null; /** - * Used in test mode - * - * @return + * Used in test mode. + * + * @return the hash test users */ public static HashMap getHashTestUsers() { @@ -87,7 +88,7 @@ public class GWTWorkspaceSharingBuilder { hashTestUser.put("valentina.marioli", new InfoContactModel( "valentina.marioli", "valentina.marioli", "Valentina Marioli", false)); - + hashTestUser.put("devVRE", new InfoContactModel( "devVRE", "devVRE", "devVRE", true)); @@ -103,17 +104,20 @@ public class GWTWorkspaceSharingBuilder { } /** - * @param infoContactModel + * Sets the user logged. + * + * @param infoContactModel the new user logged */ public void setUserLogged(InfoContactModel infoContactModel) { this.userLogged = infoContactModel; } /** - * - * @param list - * @return - * @throws InternalErrorException + * Builds the gxt list contacts model from gcube group. + * + * @param list the list + * @return the list + * @throws InternalErrorException the internal error exception */ public List buildGXTListContactsModelFromGcubeGroup(List list) throws InternalErrorException { @@ -159,13 +163,14 @@ public class GWTWorkspaceSharingBuilder { return listContactsModel; } - + /** - * - * @param voPath - * @param list - * @return - * @throws InternalErrorException + * Builds the gxt list contacts model from v os. + * + * @param listVO the list vo + * @param voPath the vo path + * @return the list + * @throws InternalErrorException the internal error exception */ public List buildGXTListContactsModelFromVOs(List listVO, String voPath) throws InternalErrorException { @@ -174,11 +179,11 @@ public class GWTWorkspaceSharingBuilder { if(voPath==null){ voPath=ConstantsSharing.PATH_SEPARATOR; } - + if(voPath!=null && !voPath.endsWith(ConstantsSharing.PATH_SEPARATOR)){ voPath+=ConstantsSharing.PATH_SEPARATOR; } - + if (listVO == null){ logger.warn("List is null, returning"); return listContactsModel; @@ -190,20 +195,21 @@ public class GWTWorkspaceSharingBuilder { for (VO vo : listVO) { List vres = vo.getVres(); - + logger.trace("vo getGroupName: "+ vo.getGroupName()); logger.trace("vo getName: "+ vo.getName()); logger.trace("Building list contact model..."); - + if(vres!=null){ logger.trace("vres from VO "+vo.getName() +" having size :" +vres.size() +", converting"); for (VRE vre : vres) { - + if(vre.getName()!=null || !vre.getName().isEmpty()){ String groupId = voPath+vre.getName(); - InfoContactModel contact = new InfoContactModel(groupId, groupId, vre.getName(), true); - logger.trace("Adding group contact " + contact); - listContactsModel.add(contact); + logger.trace("adding contact groupId: "+groupId +" VRE name: "+vre.getName()); +// InfoContactModel contact = new InfoContactModel(groupId, groupId, vre.getName(), true); +// logger.trace("Adding group contact " + contact); +// listContactsModel.add(contact); } } }else @@ -216,6 +222,13 @@ public class GWTWorkspaceSharingBuilder { return listContactsModel; } + /** + * Builds the gxt list contacts model from user model. + * + * @param listUsers the list users + * @return the list + * @throws InternalErrorException the internal error exception + */ public List buildGXTListContactsModelFromUserModel( List listUsers) throws InternalErrorException { @@ -247,9 +260,10 @@ public class GWTWorkspaceSharingBuilder { } /** - * - * @param listPortalLogin - * @return + * Builds the gxt info contacts from portal logins. + * + * @param listPortalLogin the list portal login + * @return the list */ public List buildGxtInfoContactsFromPortalLogins(List listPortalLogin) { @@ -261,27 +275,53 @@ public class GWTWorkspaceSharingBuilder { } /** - * - * @param portalLogin - * @return + * Builds the gxt info contact from portal login. + * + * @param portalLogin the portal login + * @return the info contact model */ protected InfoContactModel buildGxtInfoContactFromPortalLogin(String portalLogin) { if (portalLogin == null) { - logger.warn("portal login is null, return empty"); + logger.warn("Contact login is null, return empty"); portalLogin = ""; } - - // TODO ISGROUP return new InfoContactModel(portalLogin, portalLogin,UserUtil.getUserFullName(portalLogin), false); + } + + /** + * Builds the gxt info contact from portal group. + * + * @param grouoLogin the grouo login + * @return the info contact model + */ + protected InfoContactModel buildGxtInfoContactFromPortalGroup(String grouoLogin) { + + String groupName = ""; + if (grouoLogin == null) { + logger.warn("GroupLogin is null, return empty"); + grouoLogin = ""; + } + + //RECOVERING VRE NAME + if(grouoLogin.contains("/")){ + int start = grouoLogin.lastIndexOf("/"); + int end = grouoLogin.length(); + if(start buildGxtInfoContactFromPortalLoginTestMode(List listPortalLogin) { @@ -295,10 +335,11 @@ public class GWTWorkspaceSharingBuilder { } /** - * - * @param user - * @return - * @throws InternalErrorException + * Builds the gxt info contact model. + * + * @param user the user + * @return the info contact model + * @throws InternalErrorException the internal error exception */ public InfoContactModel buildGXTInfoContactModel(User user) throws InternalErrorException { @@ -311,6 +352,14 @@ public class GWTWorkspaceSharingBuilder { return new InfoContactModel(); } + /** + * Builds the gxt file model item. + * + * @param item the item + * @param parentFolderModel the parent folder model + * @return the file model + * @throws Exception the exception + */ protected FileModel buildGXTFileModelItem(WorkspaceItem item, FileModel parentFolderModel) throws Exception { FileModel fileModel = null; @@ -366,6 +415,13 @@ public class GWTWorkspaceSharingBuilder { } + /** + * Sets the folder item type. + * + * @param fileModel the file model + * @param worspaceFolderItem the worspace folder item + * @return the file model + */ protected FileModel setFolderItemType(FileModel fileModel, FolderItem worspaceFolderItem) { @@ -439,6 +495,13 @@ public class GWTWorkspaceSharingBuilder { return fileModel; } + /** + * Gets the workspace acl from ac ls. + * + * @param types the types + * @return the workspace acl from ac ls + * @throws Exception the exception + */ public List getWorkspaceACLFromACLs(List types) throws Exception { List acls = new ArrayList(); @@ -481,20 +544,22 @@ public class GWTWorkspaceSharingBuilder { return acls; } - + /** - * @param aclOwner - * @return + * Gets the formatted html acl from ac ls. + * + * @param aclOwner the acl owner + * @return the formatted html acl from ac ls */ public String getFormattedHtmlACLFromACLs(Map> aclOwner) { - + String html = "
"; - + logger.trace("Formatting "+aclOwner.size() +" ACL/s"); - + for (ACLType type : aclOwner.keySet()) { List listLogins = aclOwner.get(type); - + html+=""+type+": "; html+=""; for (String login : listLogins) { @@ -508,8 +573,8 @@ public class GWTWorkspaceSharingBuilder { html+="
"; } html+="
"; - - + + return html; } diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/WorkspaceSharingServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/WorkspaceSharingServiceImpl.java index b9fcd9b..ca89377 100644 --- a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/WorkspaceSharingServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/WorkspaceSharingServiceImpl.java @@ -51,8 +51,8 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements WorkspaceSharingService { protected static Logger logger = LoggerFactory.getLogger(WorkspaceSharingServiceImpl.class); - - + + /** * Gets the GWT workspace builder. * @@ -75,27 +75,27 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements { return WsUtil.getWorkspace(this.getThreadLocalRequest().getSession()); } - + /** * Gets the notification producer. * * @return the notification producer */ protected NotificationsProducer getNotificationProducer(){ - + return WsUtil.getNotificationProducer(WsUtil.getAslSession(this.getThreadLocalRequest().getSession())); } - + /** * Gets the scope util filter. * * @return the scope util filter */ protected ScopeUtility getScopeUtilFilter(){ - + return WsUtil.getScopeUtilFilter(this.getThreadLocalRequest().getSession()); } - + /** * Checks if is test mode. * @@ -104,19 +104,19 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements protected boolean isTestMode(){ return !WsUtil.isWithinPortal(); //IS NOT INTO PORTAL } - + /* (non-Javadoc) * @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService#getAllContacts(boolean, boolean) */ @Override public List getAllContacts(boolean readGroupsFromHL, boolean readGroupsFromPortal) throws Exception { - + try { ASLSession aslSession = WsUtil.getAslSession(this.getThreadLocalRequest().getSession()); //THIS FORCE THE SESSION CREATION logger.info("Get all contacts"); - + GWTWorkspaceSharingBuilder builder = getGWTWorkspaceBuilder(); - + if(isTestMode()){ logger.warn("WORKSPACE PORTLET IS IN TEST MODE - RETURN TEST USERS AND GROUPS"); GWTWorkspaceSharingBuilder.getHashTestUsers(); @@ -138,10 +138,10 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements List listContactsModel = builder.buildGXTListContactsModelFromUserModel(userManag.listUsersByGroup(groupId)); */ List users = UserUtil.getOrganizationUsers(aslSession.getScope()); - + if(users==null) throw new Exception("An error occurred on recovering users from Portal, try again later"); - + List listContactsModel = builder.buildGXTListContactsModelFromUserModel(users); if(readGroupsFromHL){ @@ -154,18 +154,18 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements listContactsModel.addAll(builder.buildGXTListContactsModelFromGcubeGroup(groups)); }else logger.warn("Read group names from HL, return list null, skipping"); - } - + } + if(readGroupsFromPortal){ logger.info("Reading group names as scopes from Infrastructure.."); - + PortalContext context = PortalContext.getConfiguration(); logger.info("context.getInfrastructureName(): "+context.getInfrastructureName()); logger.info("aslSession.getGroupName(): "+ aslSession.getGroupName()); logger.info("aslSession.getScope().toString(): "+ aslSession.getScope()); try{ ScopeUtility scopeUtility = new ScopeUtility(aslSession.getScope()); - + if(scopeUtility.getVoName()!=null){ logger.info("VO name is not null, trying to calculate List VO"); List lsVOs = WsUtil.getVresFromInfrastructure(context.getInfrastructureName(), scopeUtility.getVoName()); @@ -173,15 +173,15 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements listContactsModel.addAll(builder.buildGXTListContactsModelFromVOs(lsVOs, scopeUtility.getVo())); }else logger.warn("VO name is null, skipping list VO "+ aslSession.getGroupName()); - + }catch(Exception e){ logger.warn("An error occurred on recovering vo name, skipping list VO "+ aslSession.getGroupName()); } } - + logger.info("Get all contacts returning a list having size: "+listContactsModel.size()); return listContactsModel; - + } catch (Exception e) { logger.error("Error in server get all contacts ", e); // return new ArrayList(); @@ -194,17 +194,17 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements */ @Override public List getListUserSharedByFolderSharedId(String folderSharedId) throws Exception{ - + logger.info("getListUserSharedByFolderSharedId "+ folderSharedId); try { Workspace workspace = getWorkspace(); WorkspaceItem wsItem = workspace.getItem(folderSharedId); - + //TODO CHANGE TO READ ACL FROM SHARED SUBFOLDER if(isASharedFolder(wsItem, false)){ - + WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) workspace.getItem(wsItem.getIdSharedFolder()); GWTWorkspaceSharingBuilder builder = getGWTWorkspaceBuilder(); @@ -215,13 +215,13 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements if(isTestMode()) return builder.buildGxtInfoContactFromPortalLoginTestMode(listPortalLogin); - + return builder.buildGxtInfoContactsFromPortalLogins(listPortalLogin); - + } else{ logger.info("the item with id: "+folderSharedId+ " is not "+WorkspaceItemType.SHARED_FOLDER); - + //DEBUG //System.out.println("the item with id: "+folderSharedId+ " is not "+WorkspaceItemType.SHARED_FOLDER); } @@ -234,30 +234,30 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements throw new Exception(e.getMessage()); } } - + /* (non-Javadoc) * @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService#getOwnerByItemId(java.lang.String) */ @Override public InfoContactModel getOwnerByItemId(String itemId) throws Exception { - + logger.info("get Owner By ItemId "+ itemId); try { - + Workspace workspace = getWorkspace(); WorkspaceItem wsItem = workspace.getItem(itemId); GWTWorkspaceSharingBuilder builder = getGWTWorkspaceBuilder(); - + return builder.buildGXTInfoContactModel(wsItem.getOwner()); - + } catch (Exception e) { logger.error("Error in getOwnerByItemId ", e); throw new Exception(e.getMessage()); } } - + /** * Gets the AC ls. * @@ -276,7 +276,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements throw new Exception(error); } } - + /* (non-Javadoc) * @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService#getMyLogin() */ @@ -285,7 +285,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements ASLSession asl = WsUtil.getAslSession(this.getThreadLocalRequest().getSession()); return asl.getUsername(); } - + /* (non-Javadoc) * @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService#getFileModelByWorkpaceItemId(java.lang.String) */ @@ -293,35 +293,35 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements public FileModel getFileModelByWorkpaceItemId(String itemId) throws Exception { try { - + // System.out.println("Get file model by itemId: "+itemId); - + if(itemId == null || itemId.isEmpty()) - throw new Exception("Identifier is null or empty"); - + throw new Exception("Identifier is null or empty"); + Workspace workspace = getWorkspace(); - + logger.info("Get file model by itemId: "+itemId); - + WorkspaceItem wsItem = workspace.getItem(itemId); - + GWTWorkspaceSharingBuilder builder = getGWTWorkspaceBuilder(); // Long startTime = System.currentTimeMillis(); -// +// // Long endTime = System.currentTimeMillis() - startTime; // String time = String.format("%d msc %d sec", endTime, TimeUnit.MILLISECONDS.toSeconds(endTime)); // logger.debug("get child for Grid by id returning element in " + time); - + logger.info("Getting folder parent"); - + WorkspaceFolder folderParent = null; if(wsItem!=null) folderParent = wsItem.getParent(); //BUILD PARENT else throw new Exception("Workspace item not found"); - - + + FileModel parent = null; if(folderParent!=null){ logger.info("Folder parent has id: "+folderParent.getId() + " and name: "+folderParent.getName()); @@ -329,7 +329,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements } else logger.info("Folder parent for item: "+wsItem.getId() +" is null"); - + //BUILD ITEM return builder.buildGXTFileModelItem(wsItem, parent); }catch (ItemNotFoundException e){ @@ -341,7 +341,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements throw new Exception(error); } } - + /* (non-Javadoc) * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#isSessionExpired() */ @@ -350,7 +350,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements return WsUtil.isSessionExpired(this.getThreadLocalRequest().getSession()); } - + // DEBUG /** * Prints the contacts. @@ -373,25 +373,25 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements } } - + /* (non-Javadoc) * @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService#shareFolder(org.gcube.portlets.widgets.workspacesharingwidget.shared.FileModel, java.util.List, boolean, org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL) */ @Override public boolean shareFolder(FileModel folder, List listContacts, boolean isNewFolder, WorkspaceACL acl) throws Exception { - + if(isSessionExpired()) throw new SessionExpiredException(); - + try { Workspace workspace = getWorkspace(); - - logger.info("sharing item id: "+ folder.getIdentifier() - + " name: "+ folder.getName() + + logger.info("sharing item id: "+ folder.getIdentifier() + + " name: "+ folder.getName() // + " parent name: " + folder.getParentFileModel().getName() + " listContacts size: " + listContacts.size()); - + // //DEBUG //System.out.println("shareFolder "+ folder.getIdentifier() + " name: "+ folder.getName() + " parent name: " + folder.getParentFileModel().getName() + " listContacts size: " + listContacts.size()); // for (InfoContactModel infoContactModel : listContacts) { @@ -400,19 +400,19 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements // printContacts(listContacts); List listLogin = UserUtil.getListLoginByInfoContactModel(listContacts); - + WorkspaceSharedFolder sharedFolder = null; - + List listSharedContact = null; - + boolean sourceFolderIsShared = folder.isShared(); - + if(sourceFolderIsShared){ //if source folder is already share... retrieve old list of sharing to notify listSharedContact = getListUserSharedByFolderSharedId(folder.getIdentifier()); } if(listLogin.size()>0){ - + if(!isNewFolder){ sharedFolder = workspace.shareFolder(listLogin, folder.getIdentifier()); sharedFolder.setDescription(folder.getDescription()); //SET NEW DESCRIPTION @@ -420,42 +420,42 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements else sharedFolder = workspace.createSharedFolder(folder.getName(), folder.getDescription(), listLogin, folder.getParentFileModel().getIdentifier()); } - + boolean created = sharedFolder==null?false:true; if(acl!=null) setACLs(sharedFolder.getId(), listLogin, acl.getId().toString()); - + if(created){ NotificationsProducer np = getNotificationProducer(); if(!sourceFolderIsShared) {//if source folder is not already shared - + //TODO ADD NOTIFICATION // np.notifyFolderSharing(listContacts, sharedFolder); - + }else{ /*System.out.println("SHARED CONTACS: "); printContacts(listSharedContact); System.out.println("NEW CONTACS: "); printContacts(listContacts);*/ - + //TODO ADD NOTIFICATION // np.notifyAddedUsersToSharing(listSharedContact, listContacts, sharedFolder); } } - + return created; } catch (InsufficientPrivilegesException e) { logger.error("Error in shareFolder ", e); String error = "An error occurred on creating shared folder. "+ e.getMessage(); throw new Exception(error); - + } catch (ItemAlreadyExistException e) { logger.error("Error in shareFolder ", e); String error = "An error occurred on creating shared folder. "+ e.getMessage(); throw new Exception(error); - + } catch (WrongDestinationException e) { logger.error("Error in shareFolder ", e); String error = "An error occurred on creating shared folder. "+ e.getMessage(); @@ -468,7 +468,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements throw new Exception(error); } } - + /** * Sets the ac ls. * @@ -481,34 +481,34 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements try { if(folderId == null) - throw new Exception("Folder id is null"); - + throw new Exception("Folder id is null"); + if(listLogins==null || listLogins.size()==0) throw new Exception("List Logins is null or empty"); - + logger.info("Setting ACL for folder id: "+folderId); logger.info("ACL type is: "+aclType); - + Workspace workspace = getWorkspace(); WorkspaceItem wsItem = workspace.getItem(folderId); //IS A WORKSPACE FOLDER? if(wsItem!= null && wsItem.isFolder() && wsItem.isShared()){ WorkspaceFolder ite; - if(wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER)){ + if(wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER)){ //IS ROOT SHARED FOLDER ite = (WorkspaceSharedFolder) wsItem; logger.trace("Folder " +ite.getName()+" is a "+WorkspaceSharedFolder.class.getName()); - }else{ - // IS SUB FOLDER OF THE SHARING + }else{ + // IS SUB FOLDER OF THE SHARING ite = (WorkspaceFolder) wsItem; logger.trace("Folder " +ite.getName()+" is a "+WorkspaceFolder.class.getName()); } - + ite.setACL(listLogins, ACLType.valueOf(aclType)); }else throw new Exception("Source item is not shared or shared folder"); - + logger.info("Setting ACL for "+wsItem.getName()+" completed, returning"); } catch (Exception e) { logger.info("Error in set ACLs", e); @@ -522,49 +522,55 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements */ @Override public List getInfoContactModelsFromCredential(List listAlreadySharedContact) throws Exception { - + if(listAlreadySharedContact==null || listAlreadySharedContact.size()==0) throw new Exception("Credentials list is null or empty"); - - + + GWTWorkspaceSharingBuilder builder = getGWTWorkspaceBuilder(); List listContacts = new ArrayList(listAlreadySharedContact.size()); for (CredentialModel credentialModel : listAlreadySharedContact) { - + if(!credentialModel.isGroup()){ InfoContactModel contact = builder.buildGxtInfoContactFromPortalLogin(credentialModel.getLogin()); contact.setReferenceCredential(credentialModel); listContacts.add(contact); + logger.trace("Converted contact: "+credentialModel +", into: "+contact); + }else if(credentialModel.getName()==null || credentialModel.getName().isEmpty()){ + InfoContactModel contact = builder.buildGxtInfoContactFromPortalGroup(credentialModel.getLogin()); + contact.setReferenceCredential(credentialModel); + listContacts.add(contact); + logger.trace("Converted group: "+credentialModel +", into: "+contact); } } - + return listContacts; } - + /* (non-Javadoc) * @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService#getAdministratorsByFolderId(java.lang.String) */ @Override public List getAdministratorsByFolderId(String sharedFolderId) throws Exception { - + if(sharedFolderId==null || sharedFolderId.isEmpty()) throw new Exception("Shared Folder id is null or empty"); try { - + Workspace workspace = getWorkspace(); WorkspaceItem item = workspace.getItem(sharedFolderId); logger.info("Getting administator/s to folder: "+sharedFolderId); - + if(item!=null && item.getType().equals(WorkspaceItemType.SHARED_FOLDER)){ WorkspaceSharedFolder sharedFolder = (WorkspaceSharedFolder) item; GWTWorkspaceSharingBuilder builder = getGWTWorkspaceBuilder(); List admins = sharedFolder.getAdministrators(); logger.info("Converting "+admins.size()+" administator/s List"); - + if(isTestMode()) return builder.buildGxtInfoContactFromPortalLoginTestMode(admins); - + return builder.buildGxtInfoContactsFromPortalLogins(admins); }else throw new Exception("The item is null or not instanceof "+WorkspaceItemType.SHARED_FOLDER); @@ -577,75 +583,37 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements throw new Exception(error); } } - - + + /** * DEBUG. * * @return the fake groups */ private List getFakeGroups(){ - + List listContactsModel = new ArrayList(); - + PortalContext context = PortalContext.getConfiguration(); System.out.println("context.getInfrastructureName(): "+context.getInfrastructureName()); // System.out.println("context.getVOsAsString(): "+context.getVOsAsString()); List vos = WsUtil.getVresFromInfrastructure(context.getInfrastructureName(), "devsec"); - + for (VO vo : vos) { System.out.println("vo name "+vo.getName()); - + for (VRE vre : vo.getVres()) { System.out.println("vre name "+vre.getName()); listContactsModel.add(new InfoContactModel(vre.getName(), vre.getName(), vre.getName(), true)); } } - + return listContactsModel; } - - /** - * The main method. - * - * @param args the arguments - */ - public static void main(String[] args) { - - WorkspaceSharingServiceImpl impl = new WorkspaceSharingServiceImpl(); - - PortalContext context = PortalContext.getConfiguration(); - - try { - - String nameVO = "devsec"; - String vrePath = ConstantsSharing.PATH_SEPARATOR+context.getInfrastructureName() + ConstantsSharing.PATH_SEPARATOR + nameVO + ConstantsSharing.PATH_SEPARATOR; - - List lsVOs = WsUtil.getVresFromInfrastructure(context.getInfrastructureName(), nameVO); - GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder(); - List groups = builder.buildGXTListContactsModelFromVOs(lsVOs, vrePath); - - for (VO vo : lsVOs) { - System.out.println(vo.getName()); - - for (VRE vre : vo.getVres()) { - System.out.println("VRE: "+vre.getName()); - } - } - - for (InfoContactModel infoContactModel : groups) { - System.out.println(infoContactModel); - } - - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } /* (non-Javadoc) * @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService#getACLForSharedItemId(java.lang.String) - * + * * return the WorkspaceACL of shared folder, null otherwise */ @Override @@ -656,38 +624,38 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements return null; } try { - + Workspace workspace = getWorkspace(); WorkspaceItem item = workspace.getItem(itemID); - + if(isASharedFolder(item, false)){ //IS A SHARED FOLDER - + //TODO REMOVE PARENT SHARED FOLDER // WorkspaceSharedFolder parentSharedFolder = (WorkspaceSharedFolder) workspace.getItem(item.getIdSharedFolder()); WorkspaceSharedFolder sharedFolder = (WorkspaceSharedFolder) item; GWTWorkspaceSharingBuilder builder = getGWTWorkspaceBuilder(); - + logger.info("Read getPrivilege from HL: "+sharedFolder.getACLUser()); List wsAcls = builder.getWorkspaceACLFromACLs(Arrays.asList(sharedFolder.getACLUser())); - + if(wsAcls==null || wsAcls.isEmpty()){ logger.info("Converted ACLBySharedFolderId is null or empty, returning null"); return null; } - + logger.info("Returning first acl with id: "+wsAcls.get(0).getId()); return wsAcls.get(0); - + }else throw new Exception("The item is null or not a shared folder"); - + } catch (Exception e) { logger.error("Error in server getACLForSharedItemId", e); String error = "Sorry an error occurred when getting ACL for item: "+itemID; throw new Exception(error); } } - + /** * Gets the AC ls description for shared folder id. * @@ -698,7 +666,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements @Override public String getACLsDescriptionForSharedFolderId(String folderId) throws Exception{ try { - + WorkspaceFolder wsFolder = getSharedFolderForId(folderId); GWTWorkspaceSharingBuilder builder = getGWTWorkspaceBuilder(); return builder.getFormattedHtmlACLFromACLs(wsFolder.getACLOwner()); @@ -708,7 +676,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements throw new Exception(error); } } - + /** * Gets the shared folder for id. * @@ -717,36 +685,36 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements * @throws Exception the exception */ private WorkspaceFolder getSharedFolderForId(String folderId) throws Exception{ - + if(folderId == null) - throw new Exception("Folder id is null"); - + throw new Exception("Folder id is null"); + logger.trace("Get SharedFolderForId: "+folderId); - + Workspace workspace = getWorkspace(); WorkspaceItem wsItem = null; - + try{ wsItem = workspace.getItem(folderId); }catch(Exception e){ logger.error("Get SharedFolderForId error on folder id: "+folderId, e); throw new Exception("Sorry, an error has occurred on the server when retrieving item with id: "+folderId+". Try again later!"); } - + if(isASharedFolder(wsItem, false)){ logger.trace("Get SharedFolderForId: folder id "+folderId+" is shared"); - + //TODO REMOVE wsItem.getIdSharedFolder() // WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) workspace.getItem(wsItem.getIdSharedFolder()); WorkspaceFolder wsFolder = (WorkspaceFolder) workspace.getItem(wsItem.getId()); - + if(wsFolder!=null){ logger.info("Get SharedFolderForId return name: "+wsFolder.getName()); return wsFolder; - + //TODO USE THIS // return (WorkspaceFolder) wsItem; - + }else{ logger.warn("Source item is not a shared folder, throw exception"); throw new Exception("Source item is not a shared folder"); @@ -756,7 +724,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements throw new Exception("Source item is null or not shared for id: "+folderId); } } - + /** * Checks if is a shared folder. * @@ -764,24 +732,24 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements * @param asRoot true check if itemID is root, not otherwise * @return true, if is a shared folder */ - + public boolean isASharedFolder(String itemID, boolean asRoot){ try { - + if(itemID==null) throw new Exception("ItemId is null"); - + Workspace workspace = getWorkspace(); WorkspaceItem item = workspace.getItem(itemID); return isASharedFolder(item, asRoot); - + }catch(Exception e){ logger.error("Error in server isASharedFolder", e); return false; } } - + /** * Checks if is a shared folder. * @@ -791,18 +759,95 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements */ public boolean isASharedFolder(WorkspaceItem item, boolean asRoot){ try { - + if(item!=null && item.isFolder() && item.isShared()){ //IS A SHARED SUB-FOLDER if(asRoot) return item.getType().equals(WorkspaceItemType.SHARED_FOLDER); //IS ROOT? - + return true; } - + return false; }catch(Exception e){ logger.error("Error in server isASharedFolder", e); return false; } } + + /** + * Check list share name for group. + * + * @param listAlreadySharedContact the list already shared contact + * @return the list + */ + /*private static List checkShareNameForGroup(List listAlreadySharedContact){ + + if(listAlreadySharedContact==null) + return null; + + for (CredentialModel credentialModel : listAlreadySharedContact) { + if(credentialModel.isGroup() && (credentialModel.getName()==null || credentialModel.getName().isEmpty())){ + + //RECOVERING VRE NAME + if(credentialModel.getLogin().contains("/")){ + + int start = credentialModel.getLogin().lastIndexOf("/"); + int end = credentialModel.getLogin().length(); + + if(start lsVOs = WsUtil.getVresFromInfrastructure(root, nameVO); + GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder(); + List groups = builder.buildGXTListContactsModelFromVOs(lsVOs, vrePath); + + for (VO vo : lsVOs) { + System.out.println(vo.getName()); + + for (VRE vre : vo.getVres()) { + System.out.println("VRE: "+vre.getName()); + } + } + +// for (InfoContactModel infoContactModel : groups) { +// System.out.println(infoContactModel); +// } + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }*/ + + /*List list = new ArrayList(); + list.add(new CredentialModel(null, "test.user", false)); + list.add(new CredentialModel(null, "/gcube/devsec/devVRE", true)); + list.add(new CredentialModel(null, "francesco.mangiacrapa", false)); + list.add(new CredentialModel(null, "devVRE", true)); + list.add(new CredentialModel(null, "/gcube/devsec/NextNext", true)); + + list = checkListShareNameForGroup(list); + + for (CredentialModel credentialModel : list) { + System.out.println(credentialModel); + }*/ + } } diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/util/UserUtil.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/util/UserUtil.java index b04ffcf..a6f8735 100644 --- a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/util/UserUtil.java +++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/util/UserUtil.java @@ -17,8 +17,6 @@ import org.gcube.vomanagement.usermanagement.model.UserModel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - - /** * The Class UserUtil. * @@ -26,11 +24,11 @@ import org.slf4j.LoggerFactory; * Aug 3, 2015 */ public class UserUtil { - + static UserManager um = new LiferayUserManager(); protected static Logger logger = LoggerFactory.getLogger(UserUtil.class); - + /** * Gets the user full name. * @@ -39,22 +37,22 @@ public class UserUtil { */ public static String getUserFullName(String portalLogin){ // return user.getPortalLogin(); //for testing in eclipse - + // logger.trace("Finding full name for: "+portalLogin); - + if(portalLogin==null) return ""; - + logger.info("Get user full name for: "+portalLogin); logger.info("Into portal: "+WsUtil.isWithinPortal()); - if ((portalLogin.compareTo(WsUtil.TEST_USER) != 0) && (WsUtil.isWithinPortal())) { //skip test.user - + if (portalLogin.compareTo(WsUtil.TEST_USER) != 0 && WsUtil.isWithinPortal()) { //skip test.user + UserModel curr = null; - + try { try { curr = um.getUserByScreenName(portalLogin); - + } catch (UserManagementSystemException e) { logger.error("An error occurred in getUserFullName "+e,e); } catch (UserRetrievalFault e) { @@ -67,24 +65,22 @@ public class UserUtil { logger.warn("Return portal login "+portalLogin); return portalLogin; } - + if (curr != null){ - // logger.trace("Return "+curr.getFullname() +" full name for: "+portalLogin); return curr.getFullname(); - } }else{ - - logger.info("Return "+WsUtil.TEST_USER_FULL_NAME +" full name for: "+portalLogin); - return WsUtil.TEST_USER_FULL_NAME; + + logger.info("We are out of portal, returning login portalLogin "+portalLogin+ "as full name"); + return portalLogin; } - + logger.info("Return portal login as full name for: "+portalLogin); return portalLogin; } - - + + /** * Gets the organization users. * @@ -116,7 +112,7 @@ public class UserUtil { } return null; } - + /** * Gets the list login by info contact model. * @@ -124,16 +120,16 @@ public class UserUtil { * @return the list login by info contact model */ public static List getListLoginByInfoContactModel(List listContacts){ - + List listUsers = new ArrayList(); - + for (InfoContactModel infoContactModel : listContacts) { listUsers.add(infoContactModel.getLogin()); } - + return listUsers; } - + /** * Separate users names to comma. * @@ -141,20 +137,20 @@ public class UserUtil { * @return the string */ public static String separateUsersNamesToComma(List listContacts){ - + String users = ""; - + for (int i = 0; i < listContacts.size()-1; i++) { users+= listContacts.get(i).getName() + ", "; } - + if(listContacts.size()>1) users += listContacts.get(listContacts.size()-1).getName(); - + return users; } - - + + /** * Separate full name to comma for portal login. * @@ -162,17 +158,17 @@ public class UserUtil { * @return the string */ public static String separateFullNameToCommaForPortalLogin(List listLogin){ - + String users = ""; - + for (int i = 0; i < listLogin.size()-1; i++) { users+= getUserFullName(listLogin.get(i)) + ", "; } - + if(listLogin.size()>1) users += getUserFullName(listLogin.get(listLogin.size()-1)); - + return users; } - + } diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/util/WsUtil.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/util/WsUtil.java index 978a921..83c4897 100644 --- a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/util/WsUtil.java +++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/util/WsUtil.java @@ -1,5 +1,5 @@ /** - * + * */ package org.gcube.portlets.widgets.workspacesharingwidget.server.util; @@ -32,7 +32,7 @@ import com.liferay.portal.service.UserLocalServiceUtil; /** - * + * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @Feb 18, 2014 * @@ -45,11 +45,8 @@ public class WsUtil { public static final String NOTIFICATION_PRODUCER = "NOTIFICATION_SHARING_PRODUCER"; public static final String WORKSPACE_SCOPE_UTIL = "WORKSPACE_SHARING_SCOPE_UTIL"; public static final String NOTIFICATION_PORTLET_CLASS_ID = "org.gcube.portlets.user.workspace.server.GWTWorkspaceServiceImpl"; //USE THE SAME OF WORKSPACE - - // public static final String TEST_SCOPE = "/gcube/devsec"; // public static final String TEST_USER = "pasquale.pagano"; - public static final String TEST_SCOPE = "/gcube/devsec"; // public static final String TEST_USER = "federico.defaveri"; // public static final String TEST_USER = "massimiliano.assante"; @@ -60,42 +57,38 @@ public class WsUtil { public static final String TEST_USER = "test.user"; // public static final String TEST_USER = "antonio.gioia"; public static final String TEST_USER_FULL_NAME = "Test User"; - - protected static Logger logger = LoggerFactory.getLogger(WsUtil.class); - // public static boolean withoutPortal = false; - + /** - * + * * @return true if you're running into the portal, false if in development */ public static boolean isWithinPortal() { try { UserLocalServiceUtil.getService(); return true; - } - catch (Exception ex) { + } + catch (Exception ex) { logger.info("Development Mode ON"); return false; - } + } } - + public static ASLSession getAslSession(HttpSession httpSession) { String sessionID = httpSession.getId(); String user = (String) httpSession.getAttribute(USERNAME_ATTRIBUTE); ASLSession session; - + if (user == null) { - + /*USE ANOTHER ACCOUNT (OTHERWHISE BY TEST_USER) FOR RUNNING * COMMENT THIS IN DEVELOP ENVIROMENT (UNCOMMENT IN PRODUCTION)*/ user=TEST_USER; - + //UNCOMMENT THIS IN DEVELOP ENVIROMENT // user = "francesco.mangiacrapa"; - logger.warn("WORKSPACE PORTLET STARTING IN TEST MODE - NO USER FOUND - PORTLETS STARTING WITH FOLLOWING SETTINGS:"); logger.warn("session id: "+sessionID); logger.warn("TEST_USER: "+user); @@ -103,38 +96,30 @@ public class WsUtil { logger.warn("USERNAME_ATTRIBUTE: "+USERNAME_ATTRIBUTE); session = SessionManager.getInstance().getASLSession(sessionID, user); session.setScope(TEST_SCOPE); - //MANDATORY FOR SOCIAL LIBRARY session.setUserAvatarId(user + "Avatar"); session.setUserFullName(TEST_USER_FULL_NAME); session.setUserEmailAddress(user + "@mail.test"); - //SET HTTP SESSION ATTRIBUTE httpSession.setAttribute(USERNAME_ATTRIBUTE, user); - // withoutPortal = true; - return session; - + }else if(user.compareToIgnoreCase(TEST_USER)==0){ - // withoutPortal = true; - //COMMENT THIS IN PRODUCTION ENVIROMENT // }else if(user.compareToIgnoreCase("francesco.mangiacrapa")==0){ -// // withoutPortal = false; // END UNCOMMENT }else{ - // withoutPortal = false; } - + return SessionManager.getInstance().getASLSession(sessionID, user); } - + /** - * + * * @param httpSession * @return true if current username into ASL session is WsUtil.TEST_USER, false otherwise * @throws Exception @@ -144,23 +129,23 @@ public class WsUtil { //READING USERNAME FROM ASL SESSION String userUsername = getAslSession(httpSession).getUsername(); boolean isTestUser = userUsername.compareTo(WsUtil.TEST_USER)==0; - + //TODO UNCOMMENT THIS FOR RELEASE logger.info("Is "+WsUtil.TEST_USER+" test user? "+isTestUser); - + if(isTestUser){ logger.error("workspace session is expired! username is: "+WsUtil.TEST_USER); return true; //is TEST_USER, session is expired } logger.info("workspace session is valid! current username is: "+userUsername); - + return false; - + } - + /** - * + * * @param infrastructure the infrastructure name * @param startScopes the starting scopes * @return an arraylist of VO containing their child VREs @@ -188,30 +173,30 @@ public class WsUtil { } return toReturn; } - + public static Workspace getWorkspace(final HttpSession httpSession) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException { - + logger.info("Get Workspace"); final ASLSession session = getAslSession(httpSession); logger.info("ASLSession scope: "+session.getScope() + " username: "+session.getUsername()); ScopeProvider.instance.set(session.getScope()); logger.info("Scope provider instancied"); - + Workspace workspace = HomeLibrary.getUserWorkspace(session.getUsername()); if (session.getAttribute(WORKSPACEBUILDER_ATTRIBUTE) == null) { logger.info("Initializing the workspace area builder"); - + GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder(); - - //ADDED 03/09/2013 + + //ADDED 03/09/2013 //TODO IS GROUP? builder.setUserLogged(new InfoContactModel(session.getUsername(), session.getUsername(), session.getUserFullName(), false)); - + session.setAttribute(WORKSPACEBUILDER_ATTRIBUTE, builder); } @@ -221,9 +206,9 @@ public class WsUtil { public static NotificationsManager getNotificationManager(ASLSession session) { - + NotificationsManager notifMng = (NotificationsManager) session.getAttribute(NOTIFICATION_MANAGER); - + if (notifMng == null) { try{ logger.info("Create new NotificationsManager for user: "+session.getUsername()); @@ -234,62 +219,62 @@ public class WsUtil { logger.error("An error occurred instancing ApplicationNotificationsManager for user: "+session.getUsername(),e); } } - + return notifMng; } - + public static NotificationsProducer getNotificationProducer(ASLSession session) { - + NotificationsProducer notifProducer = (NotificationsProducer) session.getAttribute(NOTIFICATION_PRODUCER); - + if (notifProducer == null) { logger.info("Create new Notification Producer for user: "+session.getUsername()); notifProducer = new NotificationsProducer(session); session.setAttribute(NOTIFICATION_PRODUCER, notifProducer); } - + return notifProducer; } public static String getUserId(HttpSession httpSession) { - + ASLSession session = getAslSession(httpSession); - + return session.getUsername(); } - + public static boolean isVRE(ASLSession session){ - + String currentScope = session.getScopeName(); - + int slashCount = StringUtils.countMatches(currentScope, "/"); - + if(slashCount < 3){ logger.info("currentScope is not VRE"); return false; } - + logger.info("currentScope is VRE"); return true; - + } - + public static ScopeUtility getScopeUtilFilter(HttpSession httpSession){ - + ASLSession session = getAslSession(httpSession); ScopeUtility scopeUtil = null; try{ scopeUtil = (ScopeUtility) session.getAttribute(WsUtil.WORKSPACE_SCOPE_UTIL); - + if(scopeUtil==null){ scopeUtil = new ScopeUtility(session.getScopeName()); - + } }catch (Exception e) { logger.error("an error occurred in getscope filter ",e); } - + return scopeUtil; } @@ -300,16 +285,16 @@ public class WsUtil { public static GWTWorkspaceSharingBuilder getGWTWorkspaceSharingBuilder(HttpSession httpSession) { ASLSession session = getAslSession(httpSession); GWTWorkspaceSharingBuilder builder = null; - + try{ builder = (GWTWorkspaceSharingBuilder) session.getAttribute(WsUtil.WORKSPACEBUILDER_ATTRIBUTE); - + if(builder==null) return new GWTWorkspaceSharingBuilder(); }catch (Exception e) { logger.error("an error occurred in get builder ",e); } - + return new GWTWorkspaceSharingBuilder(); } } diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/shared/CredentialModel.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/shared/CredentialModel.java index 3222389..04ae425 100644 --- a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/shared/CredentialModel.java +++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/shared/CredentialModel.java @@ -1,61 +1,141 @@ /** - * + * */ package org.gcube.portlets.widgets.workspacesharingwidget.shared; import java.io.Serializable; + /** - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * @Mar 3, 2014 + * The Class CredentialModel. * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Apr 14, 2016 */ public class CredentialModel implements Serializable{ - + /** - * + * */ - private static final long serialVersionUID = -4265499048265553603L; - + private static final long serialVersionUID = 5312392409290548813L; + private String id; private String login; private boolean isGroup; - - public CredentialModel(){ - - } + private String name; + /** - * @param id - * @param login - * @param isGroup + * Instantiates a new credential model. + */ + public CredentialModel(){ + + } + + /** + * Instantiates a new credential model. + * + * @param id the id + * @param login the login + * @param isGroup the is group */ public CredentialModel(String id, String login, boolean isGroup) { this.id = id; this.login = login; this.isGroup = isGroup; } - + + /** + * Instantiates a new credential model. + * + * @param id the id + * @param login the login + * @param name the name + * @param isGroup the is group + */ + public CredentialModel(String id, String login, String name, boolean isGroup) { + this(id,login,isGroup); + this.name = name; + } + + /** + * Gets the name. + * + * @return the name + */ + public String getName() { + + return name; + } + + /** + * Sets the name. + * + * @param name the name to set + */ + public void setName(String name) { + + this.name = name; + } + + /** + * Gets the id. + * + * @return the id + */ public String getId() { return id; } + + /** + * Gets the login. + * + * @return the login + */ public String getLogin() { return login; } + + /** + * Checks if is group. + * + * @return true, if is group + */ public boolean isGroup() { return isGroup; } + + /** + * Sets the id. + * + * @param id the new id + */ public void setId(String id) { this.id = id; } + + /** + * Sets the login. + * + * @param login the new login + */ public void setLogin(String login) { this.login = login; } + + /** + * Sets the group. + * + * @param isGroup the new group + */ public void setGroup(boolean isGroup) { this.isGroup = isGroup; } - + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ @Override public String toString() { + StringBuilder builder = new StringBuilder(); builder.append("CredentialModel [id="); builder.append(id); @@ -63,8 +143,9 @@ public class CredentialModel implements Serializable{ builder.append(login); builder.append(", isGroup="); builder.append(isGroup); + builder.append(", name="); + builder.append(name); builder.append("]"); return builder.toString(); } - }