From 193f40e45047fc5bd7b27b231c96832c5179818f Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Wed, 13 Mar 2019 15:49:58 +0000 Subject: [PATCH] implemented check on numbner of batches git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/branches/portlets/user/PerformFISH-Apps/1.3@178571 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 1 + .settings/org.eclipse.jdt.core.prefs | 1 + .../performfish/CompanyFarmRepository.java | 124 ++++++------ .../performfish/CompanyPrivateRepository.java | 16 +- .../util/ImportedBatchChecker.java | 182 ++++++++++++++++++ .../portlets/user/performfish/util/Utils.java | 38 +++- .../farmrepository/view_farm_repository.jsp | 93 ++++++++- 7 files changed, 381 insertions(+), 74 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/performfish/util/ImportedBatchChecker.java diff --git a/.classpath b/.classpath index 26981b6..04023d0 100644 --- a/.classpath +++ b/.classpath @@ -15,6 +15,7 @@ + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 13b3428..91ca62e 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -10,4 +10,5 @@ org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.source=1.8 diff --git a/src/main/java/org/gcube/portlets/user/performfish/CompanyFarmRepository.java b/src/main/java/org/gcube/portlets/user/performfish/CompanyFarmRepository.java index 8183142..3fb1d2b 100644 --- a/src/main/java/org/gcube/portlets/user/performfish/CompanyFarmRepository.java +++ b/src/main/java/org/gcube/portlets/user/performfish/CompanyFarmRepository.java @@ -3,14 +3,12 @@ package org.gcube.portlets.user.performfish; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; -import java.net.URI; import java.net.URL; import java.net.URLEncoder; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -44,8 +42,6 @@ import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder; import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException; import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile; -import org.gcube.common.resources.gcore.GCoreEndpoint; -import org.gcube.common.resources.gcore.GCoreEndpoint.Profile.Endpoint; import org.gcube.common.storagehub.client.StreamDescriptor; import org.gcube.common.storagehub.client.dsl.StorageHubClient; import org.gcube.common.storagehub.client.plugins.AbstractPlugin; @@ -54,6 +50,7 @@ import org.gcube.common.storagehub.model.items.Item; import org.gcube.common.storagehub.model.service.Version; import org.gcube.portlets.user.performfish.bean.PublishAnonymisedJob; import org.gcube.portlets.user.performfish.bean.SubmittedForm; +import org.gcube.portlets.user.performfish.util.ImportedBatchChecker; import org.gcube.portlets.user.performfish.util.PFISHConstants; import org.gcube.portlets.user.performfish.util.Utils; import org.gcube.portlets.user.performfish.util.comparators.WSItemComparator; @@ -75,7 +72,8 @@ import com.liferay.portal.util.PortalUtil; import com.liferay.util.bridges.mvc.MVCPortlet; /** - * Portlet implementation class CompanyFarmRepository + * + * @author M. Assante CNR-ISTI */ public class CompanyFarmRepository extends MVCPortlet { public static final String PHASE_PREFERENCE_ATTR_NAME = "phase"; @@ -172,7 +170,7 @@ public class CompanyFarmRepository extends MVCPortlet { List toReturn = new ArrayList<>(); String authorizationToken = Utils.getCurrentUserToken(context, Utils.getCurrentUser(renderRequest).getUsername()); - String analyticalToolkitServiceURL = getAnalyticalToolkitEndpoint(context) ; + String analyticalToolkitServiceURL = Utils.getAnalyticalToolkitEndpoint(context) ; SecurityTokenProvider.instance.set(authorizationToken); StringBuilder sb = new StringBuilder(analyticalToolkitServiceURL) .append("/import/") @@ -266,17 +264,25 @@ public class CompanyFarmRepository extends MVCPortlet { //if download version String versionDownloadItemId = ParamUtil.getString(resourceRequest, "versionDownloadItemId", null); String versionDownloadName = ParamUtil.getString(resourceRequest, "versionDownloadName", null); + + String fileToPublishId = ParamUtil.getString(resourceRequest, "fileToPublishId", null); + String farmIdString = ParamUtil.getString(resourceRequest, "farmId", null); String authToken = setAuthorizationToken(resourceRequest); //check if is a file download if (fileToDownloadId != null) { String selectedItemId = fileToDownloadId; - ItemManagerClient client = AbstractPlugin.item().build(); - StreamDescriptor streamDescr = client.download(selectedItemId); - HttpServletResponse httpRes = PortalUtil.getHttpServletResponse(resourceResponse); - HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(resourceRequest); - ServletResponseUtil.sendFile(httpReq,httpRes, streamDescr.getFileName(), streamDescr.getStream(), "application/download"); - streamDescr.getStream().close(); + try { + ItemManagerClient client = AbstractPlugin.item().build(); + StreamDescriptor streamDescr = client.download(selectedItemId); + HttpServletResponse httpRes = PortalUtil.getHttpServletResponse(resourceResponse); + HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(resourceRequest); + ServletResponseUtil.sendFile(httpReq,httpRes, streamDescr.getFileName(), streamDescr.getStream(), "application/download"); + streamDescr.getStream().close(); + } + catch (Exception e) { + e.printStackTrace(); + } } else if (versionDownloadItemId != null && versionDownloadName != null) { //check if download version GCubeUser currentUser = Utils.getCurrentUser(resourceRequest); @@ -295,28 +301,58 @@ public class CompanyFarmRepository extends MVCPortlet { } catch (ItemNotFoundException | InternalErrorException e) { e.printStackTrace(); } - } else { - String fileToPublishId = ParamUtil.getString(resourceRequest, "fileToPublishId", null); - String farmIdString = ParamUtil.getString(resourceRequest, "farmId", null); + } + else if (fileToPublishId != null && farmIdString != null) { //check if is publish and anonimyse long farmId = Long.parseLong(farmIdString); + try { + ItemManagerClient client = AbstractPlugin.item().build(); + Item selectedForm = client.get(fileToPublishId, "hl:accounting"); - ItemManagerClient client = AbstractPlugin.item().build(); - Item selectedForm = client.get(fileToPublishId, "hl:accounting"); + String publicLink = client.getPublickLink(fileToPublishId).toString(); + List versions = client.getFileVersions(fileToPublishId); + String theVersion = "1.0"; + for (Version version : versions) { + if (version.isCurrent()) + theVersion = version.getName(); + } + _log.debug("Publish and Anonymise " + selectedForm.getName()); + String batchType = Utils.getBatchTypeName(Utils.getPhaseByFileName(selectedForm.getName()), selectedForm.getName()); - String publicLink = client.getPublickLink(fileToPublishId).toString(); - List versions = client.getFileVersions(fileToPublishId); - String theVersion = "1.0"; - for (Version version : versions) { - if (version.isCurrent()) - theVersion = version.getName(); + String result = submitPublishAndAnonymise(resourceRequest, farmId, publicLink, theVersion, batchType, authToken); + JSONObject fileObject = JSONFactoryUtil.createJSONObject(); + fileObject.put("success", result); + resourceResponse.getWriter().println(fileObject); } - _log.debug("Publish and Anonymise " + selectedForm.getName()); - String batchType = Utils.getBatchTypeName(Utils.getPhaseByFileName(selectedForm.getName()), selectedForm.getName()); - - String result = submitPublishAndAnonymise(resourceRequest, farmId, publicLink, theVersion, batchType, authToken); - JSONObject fileObject = JSONFactoryUtil.createJSONObject(); - fileObject.put("success", result); - resourceResponse.getWriter().println(fileObject); + catch (Exception e) { + e.printStackTrace(); + } + } + else { + String batchType = ParamUtil.getString(resourceRequest, "batchType", null); + String farmIdStr = ParamUtil.getString(resourceRequest, "farmId", null); + String context = Utils.getCurrentContext(resourceRequest); + long farmId = Long.parseLong(farmIdStr); + boolean analyisisEnabled = false; + try { + analyisisEnabled = ImportedBatchChecker.checkAnalysisAvailability(farmId, batchType, context); + } + catch (Exception e) { + JSONObject fileObject = JSONFactoryUtil.createJSONObject(); + fileObject.put("success", "NOK"); + fileObject.put("message", " There was an error on the server, please report this issue"); + resourceResponse.getWriter().println(fileObject); + } + if (analyisisEnabled) { + JSONObject fileObject = JSONFactoryUtil.createJSONObject(); + fileObject.put("success", "OK"); + resourceResponse.getWriter().println(fileObject); + } else { + JSONObject fileObject = JSONFactoryUtil.createJSONObject(); + fileObject.put("success", "NOK"); + fileObject.put("message", " Low number of batches"); + resourceResponse.getWriter().println(fileObject); + } + } } @@ -355,7 +391,7 @@ public class CompanyFarmRepository extends MVCPortlet { String urlParameters = "batch_type="+batchType+"&farmid="+farmId+"&source="+encodedURL+"&source_version="+version+"&gcube-token="+token; String context = Utils.getCurrentContext(request); - String analyticalToolkitServiceURL = getAnalyticalToolkitEndpoint(context) ; + String analyticalToolkitServiceURL = Utils.getAnalyticalToolkitEndpoint(context) ; return doPOSTRequest(analyticalToolkitServiceURL, params, urlParameters); } @@ -402,31 +438,7 @@ public class CompanyFarmRepository extends MVCPortlet { } } - private static String getAnalyticalToolkitEndpoint(String context) { - List analyticalServices = null; - try { - analyticalServices = Utils.getAnalyticalToolkitServiceInstance(context); - if (analyticalServices == null || analyticalServices.isEmpty()) { - return "Cound not find Analytical Toolkit service"; - } - GCoreEndpoint endpoint = analyticalServices.get(0); - Collection list = endpoint.profile().endpoints().asCollection(); - - URI theURI = null; - for (Endpoint ep : list) { - if (ep.name().equals(Utils.ANALYTICAL_TOOLKIT_SERVICE_INTERFACE_NAME)) { - _log.info("Analytical Toolkit GCoreEndpoint: "+ep.uri()); - theURI = ep.uri(); - } - } - String endpointSSL = "https://"+theURI.getHost()+theURI.getPath(); - return endpointSSL; - - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } + private static void fixUntrustCertificate() throws KeyManagementException, NoSuchAlgorithmException{ TrustManager[] trustAllCerts = new TrustManager[]{ diff --git a/src/main/java/org/gcube/portlets/user/performfish/CompanyPrivateRepository.java b/src/main/java/org/gcube/portlets/user/performfish/CompanyPrivateRepository.java index abd4250..01fd50d 100644 --- a/src/main/java/org/gcube/portlets/user/performfish/CompanyPrivateRepository.java +++ b/src/main/java/org/gcube/portlets/user/performfish/CompanyPrivateRepository.java @@ -147,12 +147,16 @@ public class CompanyPrivateRepository extends MVCPortlet { //check if is a file download if (fileToDownloadId != null) { String selectedItemId = fileToDownloadId; - ItemManagerClient client = AbstractPlugin.item().build(); - StreamDescriptor streamDescr = client.download(selectedItemId); - HttpServletResponse httpRes = PortalUtil.getHttpServletResponse(resourceResponse); - HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(resourceRequest); - ServletResponseUtil.sendFile(httpReq,httpRes, streamDescr.getFileName(), streamDescr.getStream(), "application/download"); - streamDescr.getStream().close(); + try { + ItemManagerClient client = AbstractPlugin.item().build(); + StreamDescriptor streamDescr = client.download(selectedItemId); + HttpServletResponse httpRes = PortalUtil.getHttpServletResponse(resourceResponse); + HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(resourceRequest); + ServletResponseUtil.sendFile(httpReq,httpRes, streamDescr.getFileName(), streamDescr.getStream(), "application/download"); + streamDescr.getStream().close(); + } catch (Exception e) { + e.printStackTrace(); + } } else if (versionDownloadItemId != null && versionDownloadName != null) { //check if download version GCubeUser currentUser = Utils.getCurrentUser(resourceRequest); diff --git a/src/main/java/org/gcube/portlets/user/performfish/util/ImportedBatchChecker.java b/src/main/java/org/gcube/portlets/user/performfish/util/ImportedBatchChecker.java new file mode 100644 index 0000000..27c3d1e --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/performfish/util/ImportedBatchChecker.java @@ -0,0 +1,182 @@ +package org.gcube.portlets.user.performfish.util; + +import static org.gcube.resources.discovery.icclient.ICFactory.clientFor; +import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.StringReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; +import java.util.List; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.apache.commons.io.IOUtils; +import org.gcube.common.authorization.library.provider.SecurityTokenProvider; +import org.gcube.common.resources.gcore.GCoreEndpoint; +import org.gcube.common.resources.gcore.GenericResource; +import org.gcube.resources.discovery.client.api.DiscoveryClient; +import org.gcube.resources.discovery.client.queries.api.SimpleQuery; +import org.json.JSONException; +import org.json.JSONObject; +import org.xml.sax.InputSource; + +import com.liferay.portal.kernel.log.LogFactoryUtil; + +/** + * + * @author F. Sinibaldi CNR-ISTI + * @author M. Assante CNR-ISTI + */ +public class ImportedBatchChecker { + private static com.liferay.portal.kernel.log.Log _log = LogFactoryUtil.getLog(ImportedBatchChecker.class); + + private static String ANALYTICAL_TOOLKIT_SERVICE_GCORE_ENDPOINT_NAME = "perform-service"; + private static String ANALYTICAL_TOOLKIT_SERVICE_GCORE_ENDPOINT_CLASS = "Application"; + private static String CONFIGURATION_RESOURCE_SECONDARY_TYPE="ApplicationConfiguration"; + private static String CONFIGURATION_RESOURCE_NAME="PerformFishConfiguration"; + private static final int N_BATCHES_THRESHOLD_FALLBACK = 4; + + + public static boolean checkAnalysisAvailability(long farmid,String batchType, String context) throws JSONException, IOException, KeyManagementException, NoSuchAlgorithmException, NumberFormatException, XPathExpressionException { + fixUntrustCertificate(); + String servicecall=formServiceCall(batchType,farmid, context); + JSONObject jsonObject=readFromURL(servicecall); + String csvUrl=jsonObject.getString("BatchesTable_internal"); + long csvLines=readCSVLines(csvUrl); + return csvLines-1>getThresholdFromIS(); + } + + + private static int getThresholdFromIS() throws NumberFormatException, XPathExpressionException { + try { + SimpleQuery query = queryFor(GenericResource.class); + query.addCondition("$resource/Profile/SecondaryType/text() eq '"+ CONFIGURATION_RESOURCE_SECONDARY_TYPE+"'"); + query.addCondition("$resource/Profile/Name/text() eq '"+ CONFIGURATION_RESOURCE_NAME+"'"); + DiscoveryClient client = clientFor(GenericResource.class); + String xmlConfiguration=client.submit(query).get(0).profile().bodyAsString(); + + InputSource source = new InputSource(new StringReader(xmlConfiguration)); + XPathFactory xpathFactory = XPathFactory.newInstance(); + XPath xpath = xpathFactory.newXPath(); + + return Integer.parseInt(xpath.evaluate("//config/analysis_threshold/text()", source)); + } + catch (Exception e) { + _log.error("There was an error contacting the IS for reading the Batch threshold, returning fallback value="+N_BATCHES_THRESHOLD_FALLBACK, e); + return N_BATCHES_THRESHOLD_FALLBACK; + } + + } + + private static String formServiceCall(String batchtype, long farmid, String context) { + return new StringBuilder(Utils.getAnalyticalToolkitEndpoint(context)) + .append("/performance") + .append("?") + .append("batch_type=").append(batchtype) + .append("&gcube-token="+SecurityTokenProvider.instance.get()) + .append("&farmid=").append(farmid).toString(); + } + + + private static long readCSVLines(String csvUrl) throws IOException { + URL url= new URL(csvUrl); + HttpURLConnection conn= (HttpURLConnection) url.openConnection(); + conn.setDoOutput( true ); + conn.setInstanceFollowRedirects( true ); + conn.setRequestMethod( "GET" ); + + BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); + int lines = 0; + while (reader.readLine() != null) lines++; + reader.close(); + return lines; + } + + private static JSONObject readFromURL(String request) throws IOException, JSONException { + URL url= new URL(request); + HttpsURLConnection conn= (HttpsURLConnection) url.openConnection(); + conn.setDoOutput( true ); + conn.setInstanceFollowRedirects( false ); + conn.setRequestMethod( "GET" ); + conn.setRequestProperty( "Content-Type", "application/json"); + conn.setRequestProperty( "charset", "utf-8"); + conn.setUseCaches( false ); + + InputStream in = conn.getInputStream(); + String encoding = conn.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + + return new JSONObject(body); + } + + + private static void fixUntrustCertificate() throws KeyManagementException, NoSuchAlgorithmException{ + TrustManager[] trustAllCerts = new TrustManager[]{ + new X509TrustManager() { + public java.security.cert.X509Certificate[] getAcceptedIssuers() { + return null; + } + @Override + public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) + throws CertificateException { + } + + @Override + public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) + throws CertificateException { + } + + } + }; + + SSLContext sc = SSLContext.getInstance("SSL"); + sc.init(null, trustAllCerts, new java.security.SecureRandom()); + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + + HostnameVerifier allHostsValid = new HostnameVerifier() { + public boolean verify(String hostname, SSLSession session) { + return true; + } + }; + + // set the allTrusting verifier + HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); + } + + + + public static List getAnalyticalToolkitServiceInstance() throws Exception { + SimpleQuery query = queryFor(GCoreEndpoint.class); + query.addCondition("$resource/Profile/ServiceClass/text() eq '"+ ANALYTICAL_TOOLKIT_SERVICE_GCORE_ENDPOINT_CLASS +"'"); + query.addCondition("$resource/Profile/ServiceName/text() eq '"+ ANALYTICAL_TOOLKIT_SERVICE_GCORE_ENDPOINT_NAME +"'"); + DiscoveryClient client = clientFor(GCoreEndpoint.class); + List toReturn = client.submit(query); + return toReturn; + } + + + // public static void main(String[] args) throws JSONException, IOException, KeyManagementException, NoSuchAlgorithmException, NumberFormatException, XPathExpressionException { + // //SecurityTokenProvider.instance.set("****"); + // ScopeProvider.instance.set("/gcube/preprod/preVRE"); + // String batchtype="GROW_OUT_INDIVIDUAL"; + // long farmid=12682549; + // + // System.out.println("IS ANALYSIS AVAILABLE : "+checkAnalysisAvailability(farmid, batchtype)); + // } +} diff --git a/src/main/java/org/gcube/portlets/user/performfish/util/Utils.java b/src/main/java/org/gcube/portlets/user/performfish/util/Utils.java index 7d5d415..9f4fd98 100644 --- a/src/main/java/org/gcube/portlets/user/performfish/util/Utils.java +++ b/src/main/java/org/gcube/portlets/user/performfish/util/Utils.java @@ -6,10 +6,12 @@ import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; import java.io.IOException; import java.io.UnsupportedEncodingException; +import java.net.URI; import java.net.URLEncoder; import java.sql.Connection; import java.util.ArrayList; import java.util.Base64; +import java.util.Collection; import java.util.List; import javax.portlet.PortletException; @@ -30,6 +32,7 @@ import org.gcube.common.homelibrary.home.workspace.accessmanager.ACLType; import org.gcube.common.portal.PortalContext; import org.gcube.common.resources.gcore.GCoreEndpoint; import org.gcube.common.resources.gcore.ServiceEndpoint; +import org.gcube.common.resources.gcore.GCoreEndpoint.Profile.Endpoint; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.portlets.user.performfish.bean.Association; import org.gcube.portlets.user.performfish.bean.Company; @@ -61,7 +64,10 @@ import com.liferay.portlet.documentlibrary.model.DLFolderConstants; import com.liferay.portlet.documentlibrary.service.DLAppServiceUtil; import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil; import com.liferay.util.bridges.mvc.MVCPortlet; - +/** + * + * @author M. Assante CNR-ISTI + */ public class Utils { private static Log _log = LogFactoryUtil.getLog(Utils.class); @@ -948,9 +954,9 @@ public class Utils { } - public static List getAnalyticalToolkitServiceInstance(String scope) throws Exception { + public static List getAnalyticalToolkitServiceInstance(String context) throws Exception { String currScope = ScopeProvider.instance.get(); - ScopeProvider.instance.set(scope); + ScopeProvider.instance.set(context); SimpleQuery query = queryFor(GCoreEndpoint.class); query.addCondition("$resource/Profile/ServiceClass/text() eq '"+ ANALYTICAL_TOOLKIT_SERVICE_GCORE_ENDPOINT_CLASS +"'"); query.addCondition("$resource/Profile/ServiceName/text() eq '"+ ANALYTICAL_TOOLKIT_SERVICE_GCORE_ENDPOINT_NAME +"'"); @@ -960,6 +966,32 @@ public class Utils { return toReturn; } + public static String getAnalyticalToolkitEndpoint(String context) { + List analyticalServices = null; + try { + analyticalServices = getAnalyticalToolkitServiceInstance(context); + if (analyticalServices == null || analyticalServices.isEmpty()) { + return "Cound not find Analytical Toolkit service"; + } + GCoreEndpoint endpoint = analyticalServices.get(0); + Collection list = endpoint.profile().endpoints().asCollection(); + + URI theURI = null; + for (Endpoint ep : list) { + if (ep.name().equals(Utils.ANALYTICAL_TOOLKIT_SERVICE_INTERFACE_NAME)) { + _log.info("Analytical Toolkit GCoreEndpoint: "+ep.uri()); + theURI = ep.uri(); + } + } + String endpointSSL = "https://"+theURI.getHost()+theURI.getPath(); + return endpointSSL; + + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + public static List getDataMinerInstance(String scope) throws Exception { String currScope = ScopeProvider.instance.get(); ScopeProvider.instance.set(scope); diff --git a/src/main/webapp/html/farmrepository/view_farm_repository.jsp b/src/main/webapp/html/farmrepository/view_farm_repository.jsp index 747a5cb..87b567e 100644 --- a/src/main/webapp/html/farmrepository/view_farm_repository.jsp +++ b/src/main/webapp/html/farmrepository/view_farm_repository.jsp @@ -28,8 +28,70 @@ function closeAndReload() { $("#modalSuccess").hide(); location.reload(); } + +$(function () { + checkBatchesThreshold = function (theButton, endpoint, farmId, batchType) { + $(theButton).html(' checking batches, please wait ...'); + $.ajax({ + url : endpoint, + type : 'POST', + datatype : 'json', + data : { + farmId : farmId, + userId : Liferay.ThemeDisplay.getUserId(), + batchType : batchType, + groupId : Liferay.ThemeDisplay.getScopeGroupId() + }, + success : function(data) { + var content = JSON.parse(data); + if (content.success == "OK") { + location.href='${AnalyticalToolkitPortletEndpoint}?${batchTypeParamEncoded}=${batchTypeEncoded}&${farmIdParamEncoded}=${farmIdEncoded}'; + } + else { + $(theButton).html('' + content.message); + $(theButton).addClass("btn-warning"); + $(theButton).unbind('click'); + $(theButton).click(function(){ + alert('You have not published and anonymsed enough batches for this farm'); + }); + } + $('#publishAndAnonymise-Button').html('Anonymise and Publish'); + } + }); + + }; +}); + +/* in view_farm_repository */ +function checkBatchesThreshold3(endpoint, farmId, batchType) { + console.log("checkBatchesThreshold:" + endpoint); + $('#publishAndAnonymise-Button').html('in progress ...please wait'); + + $.ajax({ + url : endpoint, + type : 'POST', + datatype : 'json', + data : { + farmId : farmId, + userId : Liferay.ThemeDisplay.getUserId(), + fileToPublishId : fileId, + groupId : Liferay.ThemeDisplay.getScopeGroupId() + }, + success : function(data) { + var content = JSON.parse(data); + if (content.success == "OK") { + $("#modalSuccess").show(); + } + else { + $("#modalFailed").show(); + } + $('#publishAndAnonymise-Button').html('Anonymise and Publish'); + } + }); +} + @@ -131,13 +195,24 @@ function closeAndReload() { ${form.status} - - - - + + + + + +
+ +
+ <%-- --%> + +
+