From 9a9dab6c1e7824e2a24b950bb12cb0c1b0fb31db Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Thu, 26 Apr 2018 14:21:08 +0000 Subject: [PATCH] Enhancement on[Project Activity #11690] git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/workspace-task-executor-library@167241 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../common/workspacetaskexecutor/WsUtil.java | 137 ++++++++++++++++++ ...va => WorkspaceDataMinerTaskExecutor.java} | 72 ++++++++- 2 files changed, 203 insertions(+), 6 deletions(-) create mode 100644 src/main/java/org/gcube/common/workspacetaskexecutor/WsUtil.java rename src/main/java/org/gcube/common/workspacetaskexecutor/dataminer/{WorkspaceDataMinerTaskExecute.java => WorkspaceDataMinerTaskExecutor.java} (58%) diff --git a/src/main/java/org/gcube/common/workspacetaskexecutor/WsUtil.java b/src/main/java/org/gcube/common/workspacetaskexecutor/WsUtil.java new file mode 100644 index 0000000..0c546c6 --- /dev/null +++ b/src/main/java/org/gcube/common/workspacetaskexecutor/WsUtil.java @@ -0,0 +1,137 @@ +/** + * + */ +package org.gcube.common.workspacetaskexecutor; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.lang.Validate; +import org.gcube.common.homelibrary.home.HomeLibrary; +import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException; +import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; +import org.gcube.common.homelibrary.home.workspace.Properties; +import org.gcube.common.homelibrary.home.workspace.Workspace; +import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; +import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException; +import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + + +/** + * The Class WsUtil. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Apr 26, 2018 + */ +public class WsUtil { + + private static Logger logger = LoggerFactory.getLogger(WsUtil.class); + + + /** + * Gets the workspace. + * + * @param username the username + * @return the workspace + * @throws InternalErrorException the internal error exception + * @throws HomeNotFoundException the home not found exception + * @throws WorkspaceFolderNotFoundException the workspace folder not found exception + */ + public static Workspace getWorkspace(String username) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException{ + logger.trace("Get Workspace"); + Validate.notNull(username, "The username is null"); + return HomeLibrary.getUserWorkspace(username); + } + + + /** + * Gets the item. + * + * @param username the username + * @param itemId the item id + * @return the item + * @throws InternalErrorException the internal error exception + * @throws HomeNotFoundException the home not found exception + * @throws WorkspaceFolderNotFoundException the workspace folder not found exception + * @throws ItemNotFoundException the item not found exception + */ + public static WorkspaceItem getItem(String username, String itemId) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException, ItemNotFoundException{ + logger.trace("Get Workspace Item"); + Validate.notNull(itemId, "The itemId is null"); + return getWorkspace(username).getItem(itemId); + + } + + + /** + * Gets the properties. + * + * @param item the item + * @return the properties + */ + public static Map getProperties(WorkspaceItem item) { + + Properties properties; + try { + properties = item.getProperties(); + if (properties == null) + return null; + return properties.getProperties(); + } + catch (InternalErrorException e) { + return null; + } + } + + + /** + * Gets the properties. + * + * @param item the item + * @param propertyName the property name + * @return the properties + */ + public static String getPropertyValue(WorkspaceItem item, String propertyName){ + + Map properties = getProperties(item); + + if(properties==null) + return null; + + return properties.get(propertyName); + + } + + + /** + * Sets the property value. + * + * @param item the item + * @param propertyName the property name + * @param propertyValue the property value + * @return true, if successful + */ + public static boolean setPropertyValue(WorkspaceItem item, String propertyName, String propertyValue){ + + Map properties = getProperties(item); + try { + + if(properties==null){ + properties = new HashMap(); + } + + Properties propertiesOBJ = item.getProperties(); + properties.put(propertyName, propertyValue); + propertiesOBJ.addProperties(properties); + return true; + } + catch (InternalErrorException e) { + return false; + } + + } + +} diff --git a/src/main/java/org/gcube/common/workspacetaskexecutor/dataminer/WorkspaceDataMinerTaskExecute.java b/src/main/java/org/gcube/common/workspacetaskexecutor/dataminer/WorkspaceDataMinerTaskExecutor.java similarity index 58% rename from src/main/java/org/gcube/common/workspacetaskexecutor/dataminer/WorkspaceDataMinerTaskExecute.java rename to src/main/java/org/gcube/common/workspacetaskexecutor/dataminer/WorkspaceDataMinerTaskExecutor.java index 72e97e5..7b0a832 100644 --- a/src/main/java/org/gcube/common/workspacetaskexecutor/dataminer/WorkspaceDataMinerTaskExecute.java +++ b/src/main/java/org/gcube/common/workspacetaskexecutor/dataminer/WorkspaceDataMinerTaskExecutor.java @@ -1,25 +1,76 @@ package org.gcube.common.workspacetaskexecutor.dataminer; +import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; import org.gcube.common.workspacetaskexecutor.CheckableTask; import org.gcube.common.workspacetaskexecutor.ConfigurableTask; import org.gcube.common.workspacetaskexecutor.ExecutableTask; +import org.gcube.common.workspacetaskexecutor.TaskConfiguration; +import org.gcube.common.workspacetaskexecutor.WsUtil; import org.gcube.common.workspacetaskexecutor.shared.ItemNotExecutable; import org.gcube.common.workspacetaskexecutor.shared.dataminer.AlgorithmConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -// TODO: Auto-generated Javadoc /** - * The Class WorkspaceThreddsSynchronize. + * The Class WorkspaceDataMinerTaskExecute. * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Feb 14, 2018 + * Apr 26, 2018 */ -public class WorkspaceDataMinerTaskExecute implements ExecutableTask, ConfigurableTask, CheckableTask{ +public class WorkspaceDataMinerTaskExecutor implements ExecutableTask, ConfigurableTask, CheckableTask{ /** The logger. */ - private static Logger logger = LoggerFactory.getLogger(WorkspaceDataMinerTaskExecute.class); + private static Logger logger = LoggerFactory.getLogger(WorkspaceDataMinerTaskExecutor.class); + + private static WorkspaceDataMinerTaskExecutor INSTANCE = null; + + public static final String WS_TASK_TASK_CONF = "WS-TASK.TASK-CONF"; + + private String usernameOwner; + + + /** + * Instantiates a new workspace data miner task executor. + */ + private WorkspaceDataMinerTaskExecutor() { + } + + + /** + * With owner. + * + * @param usernameOwner the username owner + */ + public void withOwner(String usernameOwner){ + this.usernameOwner = usernameOwner; + } + + + /** + * Gets the single instance of WorkspaceDataMinerTaskExecutor. + * + * @return single instance of WorkspaceDataMinerTaskExecutor + */ + public static WorkspaceDataMinerTaskExecutor getInstance() { + if (INSTANCE == null) { + INSTANCE = new WorkspaceDataMinerTaskExecutor(); + } + return INSTANCE; + } + + + /** + * Check owner. + * + * @throws Exception the exception + */ + private void checkOwner() throws Exception { + + if(usernameOwner==null || usernameOwner.isEmpty()) + throw new Exception("You must set a valid 'usernameOwner'. Using the method #withOwner"); + + } /* (non-Javadoc) * @see org.gcube.common.workspacetaskexecutor.CheckableTask#checkItemExecutable(java.lang.String) @@ -27,10 +78,19 @@ public class WorkspaceDataMinerTaskExecute implements ExecutableTask