migrate to storagehub-wrapper first release

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-uploader@169472 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-06-26 16:37:52 +00:00
parent 7f6d0f35d8
commit d7c5b696d4
6 changed files with 160 additions and 100 deletions

32
pom.xml
View File

@ -146,17 +146,17 @@
<!-- <artifactId>home-library-jcr</artifactId> -->
<!-- <scope>provided</scope> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.gcube.common</groupId> -->
<!-- <artifactId>home-library</artifactId> -->
<!-- <scope>provided</scope> -->
<!-- <exclusions> -->
<!-- <exclusion> -->
<!-- <artifactId>asm-all</artifactId> -->
<!-- <groupId>asm</groupId> -->
<!-- </exclusion> -->
<!-- </exclusions> -->
<!-- </dependency> -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>asm-all</artifactId>
<groupId>asm</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
@ -170,11 +170,11 @@
</dependency>
<!-- LOGGER -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<scope>compile</scope>
</dependency>
<!-- <dependency> -->
<!-- <groupId>log4j</groupId> -->
<!-- <artifactId>log4j</artifactId> -->
<!-- <scope>compile</scope> -->
<!-- </dependency> -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>

View File

@ -0,0 +1,60 @@
/**
*
*/
package org.gcube.portlets.widgets.workspaceuploader.server.notification;
import org.gcube.applicationsupportlayer.social.shared.SocialFileItem;
import org.gcube.applicationsupportlayer.social.shared.SocialSharedFolder;
import org.gcube.common.storagehub.model.items.Item;
import org.gcube.common.storagehub.model.items.SharedFolder;
import org.gcube.common.storagehub.model.items.VreFolder;
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jun 26, 2018
*/
public class NotificationMapper {
protected static Logger logger = LoggerFactory.getLogger(NotificationMapper.class);
/**
* To social folder.
*
* @param sharedFolder the shared folder
* @return the social shared folder
*/
public static SocialSharedFolder toSocialFolder(SharedFolder sharedFolder){
return new SocialSharedFolder(sharedFolder.getId(), sharedFolder.getName(), sharedFolder.getTitle(), sharedFolder.getDisplayName(), sharedFolder.getPath(), sharedFolder.getParentId(), sharedFolder.isVreFolder());
}
/**
* To social item.
*
* @param storageWrapper the storage wrapper
* @param item the item
* @return the social file item
*/
public static SocialFileItem toSocialItem(StorageHubWrapper storageWrapper, Item item){
Item theFolder = null;
try {
theFolder = storageWrapper.getStorageHubClientService().getItem(item.getParentId());
}
catch (Exception e) {
logger.warn("Impossible the item using the parent id: "+item.getParentId());
}
SocialSharedFolder parent = null;
if(theFolder!=null && theFolder instanceof SharedFolder || theFolder instanceof VreFolder)
parent = toSocialFolder((SharedFolder) theFolder);
return new SocialFileItem(item.getId(), item.getName(), item.getTitle(), item.getPath(), parent);
}
}

View File

@ -9,27 +9,31 @@ import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
import org.gcube.applicationsupportlayer.social.shared.SocialFileItem;
import org.gcube.applicationsupportlayer.social.shared.SocialSharedFolder;
import org.gcube.common.storagehub.model.items.Item;
import org.gcube.common.storagehub.model.items.SharedFolder;
import org.gcube.common.storagehub.model.types.WorkspaceItemType;
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
import org.gcube.common.storagehubwrapper.server.tohl.Workspace;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder;
import org.gcube.portlets.widgets.workspaceuploader.server.util.UserUtil;
import org.gcube.portlets.widgets.workspaceuploader.shared.ContactModel;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class NotificationsWorkspaceUploader.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @May 27, 2013
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Jun 26, 2018
*/
public class NotificationsWorkspaceUploader {
protected static Logger logger = Logger.getLogger(NotificationsWorkspaceUploader.class);
protected static Logger logger = LoggerFactory.getLogger(NotificationsWorkspaceUploader.class);
/**
* Check send notify changed item to share.
@ -55,7 +59,7 @@ public class NotificationsWorkspaceUploader {
if(folderDestinationItem.isShared()){ //Notify Added Item To Sharing?
//TODO folderDestinationItem.getIdSharedFolder()
logger.trace("checkNotifyAddItemToShare source item: "+sourceItem.getName()+" sourceSharedId: "+sourceSharedId + " folder destination: "+folderDestinationItem.getName() + " folder destination shared folder id: "+folderDestinationItem.getIdSharedFolder());
logger.trace("checkNotifyAddItemToShare source item: "+sourceItem.getName()+" sourceSharedId: "+sourceSharedId + " folder destination: "+folderDestinationItem.getName() + " folder destination shared folder id: "+folderDestinationItem);
//share condition is true if source shared folder is not null
boolean shareChangeCondition = sourceSharedId==null?false:true;
@ -71,23 +75,36 @@ public class NotificationsWorkspaceUploader {
//Workspace workspace = storageWrapper.getWorkspace();
SharedFolder folderDest = (SharedFolder) folderDestinationItem;
//TODO
List<ContactModel> listContacts = getListUserSharedByFolderSharedId(storageWrapper.getWorkspace(), folderDest.getIdSharedFolder());
Item destinationSharedFolder = storageWrapper.getStorageHubClientService().getItem(folderDest.getIdSharedFolder());
List<String> listLogins = storageWrapper.getWorkspace().getSharedFolderMembers(folderDest.getId());
List<ContactModel> listContacts = new ArrayList<ContactModel>(listLogins.size());
for (String login : listLogins) {
listContacts.add(new ContactModel(login, login, false, UserUtil.getUserFullName(login)));
}
if(destinationSharedFolder instanceof WorkspaceSharedFolder){
//Item destinationSharedFolder = storageWrapper.getWorkspace().getItem(folderDest.getIdSharedFolder());
SocialFileItem socialItem = NotificationMapper.toSocialItem(storageWrapper, sourceItem);
SocialSharedFolder socialFolder = NotificationMapper.toSocialFolder(folderDest);
//SWITCH BEETWEEN ADDED OR UPDATED
if(!isOverwrite)
np.notifyAddedItemToSharing(listContacts, sourceItem, destinationSharedFolder);
np.notifyAddedItemToSharing(listContacts, socialItem, socialFolder);
else
np.notifyUpdatedItemToSharing(listContacts, sourceItem, destinationSharedFolder);
np.notifyUpdatedItemToSharing(listContacts, socialItem, socialFolder);
logger.trace("The notifies was sent correctly");
}else
logger.trace("The notifies doesn't sent because "+destinationSharedFolder+ " is not instance of WorkspaceSharedFolder");
// if(destinationSharedFolder instanceof WorkspaceSharedFolder){
//
// //SWITCH BEETWEEN ADDED OR UPDATED
// if(!isOverwrite)
// np.notifyAddedItemToSharing(listContacts, sourceItem, destinationSharedFolder);
// else
// np.notifyUpdatedItemToSharing(listContacts, sourceItem, destinationSharedFolder);
//
//
// logger.trace("The notifies was sent correctly");
// }else
// logger.trace("The notifies doesn't sent because "+destinationSharedFolder+ " is not instance of WorkspaceSharedFolder");
// np.notifyAddedItemToSharing(listContacts, (WorkspaceFolder) folderDestinationItem);
}
}
@ -101,48 +118,29 @@ public class NotificationsWorkspaceUploader {
logger.warn("The notifies is failure in checkSendNotifyAddItemToShare because folder destination item is null");
}
/**
* Gets the list user shared by folder shared id.
*
* @param workspace the workspace
* @param idSharedFolder the id shared folder
* @return the list user shared by folder shared id
* @throws Exception the exception
*/
public static List<ContactModel> getListUserSharedByFolderSharedId(Workspace workspace, String idSharedFolder) throws Exception {
logger.trace("getListUserSharedByFolderSharedId "+ idSharedFolder);
try {
WorkspaceItem wsItem = workspace.getItem(idSharedFolder);
if(isASharedFolder(wsItem)){
//TODO wsFolder.getUsers();
// WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) wsItem;
// List<String> listPortalLogin = wsFolder.getUsers();
//
//ArrayList<ContactModel> users = new ArrayList<ContactModel>(listPortalLogin.size());
ArrayList<ContactModel> users = new ArrayList<ContactModel>();
// /**
// * Gets the list user shared by folder shared id.
// *
// * @param workspace the workspace
// * @param idSharedFolder the id shared folder
// * @return the list user shared by folder shared id
// * @throws Exception the exception
// */
// public static List<ContactModel> getListUserSharedByFolderSharedId(SharedFolder folder) throws Exception {
//
// try {
// ArrayList<ContactModel> users = new ArrayList<ContactModel>(listPortalLogin.size());
// for (String login : listPortalLogin) {
// users.add(new ContactModel(login, login, false, UserUtil.getUserFullName(login)));
// }
return users;
}
else{
logger.info("the item with id: "+idSharedFolder+ " is not "+WorkspaceItemType.SHARED_FOLDER);
}
return new ArrayList<ContactModel>();
} catch (Exception e) {
logger.error("Error in getListUserSharedByItemId ", e);
throw new Exception(e.getMessage());
}
}
//
// return users;
//
// } catch (Exception e) {
// logger.error("Error in getListUserSharedByItemId ", e);
// throw new Exception(e.getMessage());
// }
// }
/**
* Checks if is a shared folder.
@ -160,9 +158,7 @@ public class NotificationsWorkspaceUploader {
/**
* Checks if is a shared folder for id.
*
* @param user the user
* @param scopeGroupId the scope group id
* @param request the request
* @param workspace the workspace
* @param itemId the item id
* @return true, if is a shared folder for id
*/

View File

@ -8,18 +8,19 @@ import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
import org.gcube.applicationsupportlayer.social.NotificationsManager;
import org.gcube.applicationsupportlayer.social.shared.SocialFileItem;
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
import org.gcube.applicationsupportlayer.social.shared.SocialSharedFolder;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.common.storagehub.model.items.Item;
import org.gcube.common.storagehub.model.items.SharedFolder;
import org.gcube.portlets.widgets.workspaceuploader.server.util.WsUtil;
import org.gcube.portlets.widgets.workspaceuploader.shared.ContactModel;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
@ -32,7 +33,7 @@ public class NotificationsWorkspaceUploaderProducer {
protected ScopeBean scope;
protected static Logger logger = Logger.getLogger(NotificationsWorkspaceUploaderProducer.class);
protected static Logger logger = LoggerFactory.getLogger(NotificationsWorkspaceUploaderProducer.class);
protected NotificationsManager notificationsMng;
@ -41,8 +42,8 @@ public class NotificationsWorkspaceUploaderProducer {
/**
* Instantiates a new notifications workspace uploader producer.
*
* @param scopeGroupId the scope group id
* @param httpSession the http session
* @param aslSession the asl session
* @param request the request
*/
public NotificationsWorkspaceUploaderProducer(String scopeGroupId, HttpSession httpSession, HttpServletRequest request) {
@ -56,7 +57,8 @@ public class NotificationsWorkspaceUploaderProducer {
/**
* Gets the notification manager.
*
* @param session the session
* @param scopeGroupId the scope group id
* @param httpSession the http session
* @param request the request
* @return the notification manager
*/
@ -104,14 +106,15 @@ public class NotificationsWorkspaceUploaderProducer {
}
/**
* Runs a new thread to notify the contacts passed in input.
*
* @param listContacts the list contacts
* @param workspaceItem the workspace item
* @param item the item
* @param sharedFolder the shared folder
*/
public void notifyAddedItemToSharing(final List<ContactModel> listContacts, final Item item, final SharedFolder sharedFolder) {
public void notifyAddedItemToSharing(final List<ContactModel> listContacts, final SocialFileItem socialItem, final SocialSharedFolder socialSharedFolder) {
new Thread() {
@Override
@ -125,14 +128,13 @@ public class NotificationsWorkspaceUploaderProducer {
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if(infoContactModel.getLogin().compareTo(username)!=0){
logger.info("Sending notification to user "+infoContactModel.getLogin() +" added item "+item.getName()+" in shared folder "+sharedFolder.getName());
logger.info("Sending notification to user "+infoContactModel.getLogin() +" added item "+socialItem.getName()+" in shared folder "+socialSharedFolder.getName());
//TODO notificationsMng.notifyAddedItem
// boolean notify = notificationsMng.notifyAddedItem(infoContactModel.getLogin(), item, sharedFolder);
//
// if(!notify){
// logger.error("An error occured when notify user: "+infoContactModel.getLogin());
// }
boolean notify = notificationsMng.notifyAddedItem(infoContactModel.getLogin(), socialItem, socialSharedFolder);
if(!notify){
logger.error("An error occured when notify user: "+infoContactModel.getLogin());
}
}
}catch (Exception e) {
logger.error("An error occured in notifyAddedItemToSharing ", e);
@ -153,7 +155,7 @@ public class NotificationsWorkspaceUploaderProducer {
* @param workspaceItem the workspace item
* @param sharedFolder the shared folder
*/
public void notifyUpdatedItemToSharing(final List<ContactModel> listContacts, final Item workspaceItem, final SharedFolder sharedFolder) {
public void notifyUpdatedItemToSharing(final List<ContactModel> listContacts, final SocialFileItem socialItem, final SocialSharedFolder socialSharedFolder) {
new Thread() {
@Override
@ -166,12 +168,12 @@ public class NotificationsWorkspaceUploaderProducer {
if(infoContactModel.getLogin().compareTo(username)!=0){
//TODO notificationsMng.notifyUpdatedItem(infoContactModel.getLogin(), workspaceItem, sharedFolder);
logger.info("Sending notification to user "+infoContactModel.getLogin() +" updated item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
/*boolean notify = notificationsMng.notifyUpdatedItem(infoContactModel.getLogin(), workspaceItem, sharedFolder);
logger.info("Sending notification to user "+infoContactModel.getLogin() +" updated item "+socialItem.getName()+" in shared folder "+socialSharedFolder.getName());
boolean notify = notificationsMng.notifyUpdatedItem(infoContactModel.getLogin(), socialItem, socialSharedFolder);
if(!notify){
logger.error("An error updated when notify user: "+infoContactModel.getLogin());
}*/
}
}
}catch (Exception e) {
logger.error("An error updated in notifyAddedItemToSharing ", e);

View File

@ -3,13 +3,14 @@ package org.gcube.portlets.widgets.workspaceuploader.server.util;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import org.gcube.portlets.widgets.workspaceuploader.shared.ContactModel;
import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -22,7 +23,7 @@ import org.gcube.vomanagement.usermanagement.model.GCubeUser;
public class UserUtil {
static UserManager um = new LiferayUserManager();
protected static Logger logger = Logger.getLogger(UserUtil.class);
protected static Logger logger = LoggerFactory.getLogger(UserUtil.class);
/**

View File

@ -6,13 +6,14 @@ package org.gcube.portlets.widgets.workspaceuploader.server.util;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.liferay.portal.service.UserLocalServiceUtil;
@ -28,7 +29,7 @@ public class WsUtil {
public static final String NOTIFICATION_MANAGER_UPLOADER = "WS_UPLOADER_NOTIFICATION_MANAGER";
public static final String NOTIFICATION_PORTLET_CLASS_ID = "org.gcube.portlets.user.workspace.server.GWTWorkspaceServiceImpl";
protected static Logger logger = Logger.getLogger(WsUtil.class);
protected static Logger logger = LoggerFactory.getLogger(WsUtil.class);
/**
* Checks if is within portal.