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
This commit is contained in:
parent
eeaae5fae4
commit
193f40e450
|
@ -15,6 +15,7 @@
|
|||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<SubmittedForm> 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<Version> 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<Version> 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<GCoreEndpoint> 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<Endpoint> 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[]{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<GenericResource> 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<GCoreEndpoint> 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<GCoreEndpoint> client = clientFor(GCoreEndpoint.class);
|
||||
List<GCoreEndpoint> 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));
|
||||
// }
|
||||
}
|
|
@ -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<GCoreEndpoint> getAnalyticalToolkitServiceInstance(String scope) throws Exception {
|
||||
public static List<GCoreEndpoint> 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<GCoreEndpoint> analyticalServices = null;
|
||||
try {
|
||||
analyticalServices = getAnalyticalToolkitServiceInstance(context);
|
||||
if (analyticalServices == null || analyticalServices.isEmpty()) {
|
||||
return "Cound not find Analytical Toolkit service";
|
||||
}
|
||||
GCoreEndpoint endpoint = analyticalServices.get(0);
|
||||
Collection<Endpoint> 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<ServiceEndpoint> getDataMinerInstance(String scope) throws Exception {
|
||||
String currScope = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(scope);
|
||||
|
|
|
@ -28,8 +28,70 @@ function closeAndReload() {
|
|||
$("#modalSuccess").hide();
|
||||
location.reload();
|
||||
}
|
||||
|
||||
$(function () {
|
||||
checkBatchesThreshold = function (theButton, endpoint, farmId, batchType) {
|
||||
$(theButton).html('<i class="icon-cog"> 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('<i class="icon-warning-sign">' + 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('<i class="icon-refresh icon-white">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');
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<portlet:resourceURL var="publishAndAnonymiseURL"></portlet:resourceURL>
|
||||
<portlet:resourceURL var="checkBatchesThresholdURL"></portlet:resourceURL>
|
||||
<portlet:renderURL var="maximizedState"
|
||||
windowState="<%=LiferayWindowState.MAXIMIZED.toString()%>" />
|
||||
<portlet:renderURL var="normalState"
|
||||
|
@ -89,7 +151,6 @@ function closeAndReload() {
|
|||
|
||||
pageContext.setAttribute("farmIdEncoded", Utils.maskId(theFarm.getTeamId()));
|
||||
pageContext.setAttribute("batchTypeEncoded", Utils.maskId(submittedForm.getBatchType()));
|
||||
|
||||
if (submittedForm.getSubmitterIdentity() != null) {
|
||||
fullNamePublisher = Utils.getUserByUsername(submittedForm.getSubmitterIdentity()).getFullname();
|
||||
pageContext.setAttribute("fullNamePublisher", fullNamePublisher);
|
||||
|
@ -104,7 +165,10 @@ function closeAndReload() {
|
|||
pageContext.setAttribute("rowBgColor", "rgb(228, 223, 0)");
|
||||
pageContext.setAttribute("buttonCheckProgressStyle", "display: visible;");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pageContext.setAttribute("fullNamePublisher", ""); //reset the field
|
||||
pageContext.setAttribute("jobEndTime", "");//reset the field
|
||||
}
|
||||
%>
|
||||
<tr style="border-bottom: 1px solid #CCC; background-color: ${rowBgColor};">
|
||||
<portlet:resourceURL var="downloadFileURL">
|
||||
|
@ -131,13 +195,24 @@ function closeAndReload() {
|
|||
<td><span
|
||||
style="margin-left: 10px; margin-right: 10px; color: #666;">${form.status}</span>
|
||||
<c:if test = "${form.status == 'COMPLETE'}">
|
||||
<c:if test = "${form.batchType == 'GROW_OUT_AGGREGATED'
|
||||
or form.batchType == 'GROW_OUT_AGGREGATED_CLOSED_BATCHES'
|
||||
or form.batchType == 'HATCHERY_AGGREGATED'}">
|
||||
<c:set var="buttonDisabled" value="disabled title='Analysis not available for this Batch type' "/>
|
||||
</c:if>
|
||||
<button class="btn" type="button" ${buttonDisabled}
|
||||
onClick="location.href='${AnalyticalToolkitPortletEndpoint}?${batchTypeParamEncoded}=${batchTypeEncoded}&${farmIdParamEncoded}=${farmIdEncoded}'">Analyse </button>
|
||||
<c:choose>
|
||||
<c:when test= "${form.batchType == 'GROW_OUT_AGGREGATED'
|
||||
or form.batchType == 'GROW_OUT_AGGREGATED_CLOSED_BATCHES'
|
||||
or form.batchType == 'HATCHERY_AGGREGATED'}">
|
||||
<button class="btn" type="button" disabled title='Analysis not available for this Batch type'>Analyse</button>
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<div style="display: inline;">
|
||||
<button class="btn" type="button"
|
||||
onClick="checkBatchesThreshold(this, '${checkBatchesThresholdURL}', '${farmId}', '${form.batchType}')">
|
||||
Analyse
|
||||
</button>
|
||||
</div>
|
||||
<%-- <button class="btn" type="button" ${buttonDisabled} --%>
|
||||
<%-- onClick="">Analyse </button> --%>
|
||||
|
||||
</c:otherwise>
|
||||
</c:choose>
|
||||
</c:if>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
Loading…
Reference in New Issue