Updated pom version at 1.4.0

Added Feature #16312
Fixed requirement "WARNING: The record is locked due to a merge request in progress."

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/grsf-manage-widget@178652 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2019-03-21 16:48:54 +00:00
parent 784882b390
commit 632e085e9e
7 changed files with 239 additions and 14 deletions

View File

@ -1,34 +1,50 @@
<ReleaseNotes>
<Changeset component="org.gcube.portlets-widgets.grsf-manage-widget.1-3-3"
date="2018-09-14">
<Change>[Feature #12255] Pop-up Text improvement for the locked records</Change>
<Changeset
component="org.gcube.portlets-widgets.grsf-manage-widget.1-4-0"
date="${buildDate}">
<Change>[Feature #16312] Report the name of the editor as tag in the
published feed</Change>
</Changeset>
<Changeset component="org.gcube.portlets-widgets.grsf-manage-widget.1-3-2"
<Changeset
component="org.gcube.portlets-widgets.grsf-manage-widget.1-3-3"
date="2018-09-14">
<Change>[Feature #12255] Pop-up Text improvement for the locked
records
</Change>
</Changeset>
<Changeset
component="org.gcube.portlets-widgets.grsf-manage-widget.1-3-2"
date="2018-03-20">
<Change>[Task #11124] Testing the GRSF management panel</Change>
</Changeset>
<Changeset component="org.gcube.portlets-widgets.grsf-manage-widget.1-3-1"
<Changeset
component="org.gcube.portlets-widgets.grsf-manage-widget.1-3-1"
date="2017-12-11">
<Change>Minor fixes</Change>
</Changeset>
<Changeset component="org.gcube.portlets-widgets.grsf-manage-widget.1-3-0"
<Changeset
component="org.gcube.portlets-widgets.grsf-manage-widget.1-3-0"
date="2017-11-11">
<Change>Some management improvements</Change>
</Changeset>
<Changeset component="org.gcube.portlets-widgets.grsf-manage-widget.1-2-0"
<Changeset
component="org.gcube.portlets-widgets.grsf-manage-widget.1-2-0"
date="2017-08-10">
<Change>Minor changes to reflect the new model of grsf records
</Change>
</Changeset>
<Changeset component="org.gcube.portlets-widgets.grsf-manage-widget.1-1-1"
<Changeset
component="org.gcube.portlets-widgets.grsf-manage-widget.1-1-1"
date="2017-04-10">
<Change>Minor improvements</Change>
</Changeset>
<Changeset component="org.gcube.portlets-widgets.grsf-manage-widget.1-1-0"
<Changeset
component="org.gcube.portlets-widgets.grsf-manage-widget.1-1-0"
date="2017-02-28">
<Change>Minor improvements</Change>
</Changeset>
<Changeset component="org.gcube.portlets-widgets.grsf-manage-widget.1-0-0"
<Changeset
component="org.gcube.portlets-widgets.grsf-manage-widget.1-0-0"
date="2017-01-31">
<Change>First Release</Change>
</Changeset>

View File

@ -12,7 +12,7 @@
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>grsf-manage-widget</artifactId>
<version>1.3.3-SNAPSHOT</version>
<version>1.4.0-SNAPSHOT</version>
<name>gCube GRSF Manage widget</name>
<scm>

View File

@ -26,6 +26,7 @@ import org.gcube.datacatalogue.grsf_manage_widget.shared.ManageProductBean;
import org.gcube.datacatalogue.grsf_manage_widget.shared.RevertableOperationInfo;
import org.gcube.datacatalogue.grsf_manage_widget.shared.SimilarGRSFRecord;
import org.gcube.datacatalogue.grsf_manage_widget.shared.SourceRecord;
import org.gcube.datacatalogue.grsf_manage_widget.shared.ex.GRSFRecordAlreadyManagedStatusException;
import org.gcube.datacatalogue.grsf_manage_widget.shared.ex.NoGRSFRecordException;
import com.github.gwtbootstrap.client.ui.AlertBlock;
@ -489,7 +490,9 @@ public class ManageProductWidget extends Composite{
if(caught instanceof NoGRSFRecordException)
showInfo(NO_GRSF_RECORD_BEAN, AlertType.WARNING);
else
else if(caught instanceof GRSFRecordAlreadyManagedStatusException) {
showInfo("WARNING: "+caught.getMessage(), AlertType.WARNING);
}else
showInfo("Error is " + caught.getMessage(), AlertType.ERROR);
// hide the form and disable the send button

View File

@ -25,6 +25,7 @@ import org.gcube.datacatalogue.grsf_manage_widget.shared.RevertableOperationInfo
import org.gcube.datacatalogue.grsf_manage_widget.shared.RevertableOperations;
import org.gcube.datacatalogue.grsf_manage_widget.shared.SimilarGRSFRecord;
import org.gcube.datacatalogue.grsf_manage_widget.shared.SourceRecord;
import org.gcube.datacatalogue.grsf_manage_widget.shared.ex.GRSFRecordAlreadyManagedStatusException;
import org.gcube.datacatalogue.grsf_manage_widget.shared.ex.NoGRSFRecordException;
import org.gcube.vomanagement.usermanagement.RoleManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
@ -221,7 +222,7 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
Status status = Status.fromString(extrasWithoutNamespaces.get(Constants.STATUS_OF_THE_GRSF_RECORD_CUSTOM_KEY).get(0));
if(status.equals(Status.To_be_Merged) && !requestForRevertingMerge)
throw new Exception("The record is locked due to a merge request in progress!");
throw new GRSFRecordAlreadyManagedStatusException(Status.To_be_Merged, "The record is locked due to a merge request in progress!");
String uuidKB = extrasWithoutNamespaces.get(Constants.UUID_KB_CUSTOM_KEY).get(0);
String grsfDomain = extrasWithoutNamespaces.get(Constants.DOMAIN_CUSTOM_KEY).get(0);

View File

@ -332,6 +332,9 @@ public class SocialCommunications {
for (String hashtag : hashtags) {
message += " #" + hashtag;
}
//Added by Francesco Mangiacrapa see at Feature #16312
String normalizedFullName = fullName.trim().replace(" ", "_");
message += " #" + normalizedFullName;
}
logger.info("The post that is going to be written is -> " + message);
@ -640,7 +643,7 @@ public class SocialCommunications {
* @return
*/
@SuppressWarnings("unchecked")
private static Map<String, Object> getResponseEntityAsJSON(HttpResponse response){
public static Map<String, Object> getResponseEntityAsJSON(HttpResponse response){
Map<String, Object> toReturn = null;
HttpEntity entity = response.getEntity();

View File

@ -0,0 +1,42 @@
package org.gcube.datacatalogue.grsf_manage_widget.shared.ex;
import org.gcube.datacatalogue.common.enums.Status;
/**
* The Class GRSFRecordAlreadyManagedStatusException.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Mar 21, 2019
*/
public class GRSFRecordAlreadyManagedStatusException extends Exception{
/**
*
*/
private static final long serialVersionUID = -2034802685606929315L;
private Status status;
/**
* Instantiates a new GRSF record already managed status exception.
*
* @param theStatus the the status
* @param arg0 the arg 0
*/
public GRSFRecordAlreadyManagedStatusException(Status theStatus, String arg0){
super(arg0);
this.status = theStatus;
}
/**
* Gets the status.
*
* @return the status
*/
public Status getStatus() {
return status;
}
}

View File

@ -0,0 +1,160 @@
package org.gcube.datacatalogue.grsf_manage_widget.client;
import static org.gcube.resources.discovery.icclient.ICFactory.client;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.util.List;
import java.util.Map;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue;
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueFactory;
import org.gcube.datacatalogue.grsf_manage_widget.server.manage.GRSFNotificationService;
import org.gcube.datacatalogue.grsf_manage_widget.server.manage.SocialCommunications;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import eu.trentorise.opendata.jackan.internal.org.apache.http.client.methods.CloseableHttpResponse;
import eu.trentorise.opendata.jackan.internal.org.apache.http.client.methods.HttpPost;
import eu.trentorise.opendata.jackan.internal.org.apache.http.entity.StringEntity;
import eu.trentorise.opendata.jackan.internal.org.apache.http.impl.client.CloseableHttpClient;
import eu.trentorise.opendata.jackan.internal.org.apache.http.impl.client.HttpClientBuilder;
import eu.trentorise.opendata.jackan.internal.org.apache.http.impl.client.LaxRedirectStrategy;
public class SendNotification {
private static String context = "/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab";
private static String token = "57b42a99-6239-44c4-9a68-591c18363222-843339462"; ///d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab
//private static String token = "8e74a17c-92f1-405a-b591-3a6090066248-98187548"; //devVRE
private static String username = "francesco.mangiacrapa";
private static final String MEDIATYPE_JSON = "application/json";
private static final Logger logger = LoggerFactory.getLogger(SendNotification.class);
// for discovering social networking service
private static final String resource = "jersey-servlet";
private static final String serviceName = "SocialNetworking";
private static final String serviceClass = "Portal";
private static final String SOCIAL_SEND_EMAIL = "2/messages/write-message";
public static void main(String[] args){
try {
ScopeProvider.instance.set(context);
SecurityTokenProvider.instance.set(token);
GRSFNotificationService grsfNotificationService = new GRSFNotificationService();
DataCatalogue catalogue = DataCatalogueFactory.getFactory().getUtilsPerScope(context);
logger.info("The Catalogue in the scope {} is {}", context, catalogue.getCatalogueUrl());
// require social networking url
final String baseUrlSocial = getBaseUrlSocialService();
logger.info("Base URL SOCIAL IS {}", baseUrlSocial);
// and the user current browser url
final String currentBrowserUrl = "http://127.0.0.1"; // ignore other parameters
// manage interactions through a separated thread but set there security token and context (and then reset them)
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try{
JSONObject message = new JSONObject();
message.put("hello", "world");
sendEmail(baseUrlSocial, "");
// create a post about the operation
//SocialCommunications.writeProductPost(baseUrlSocial, bean, username, fullName, false, currentBrowserUrl);
}catch(Exception e){
logger.error("Something failed while alerting editors/reviewers", e);
}finally{
ScopeProvider.instance.reset();
SecurityTokenProvider.instance.reset();
}
}
});
t.start();
}catch (Exception e) {
System.err.println("Error: ");
e.printStackTrace();
}
}
private static String getBaseUrlSocialService() throws Exception{
SimpleQuery query = queryFor(GCoreEndpoint.class);
query.addCondition(String.format("$resource/Profile/ServiceClass/text() eq '%s'",serviceClass));
query.addCondition("$resource/Profile/DeploymentData/Status/text() eq 'ready'");
query.addCondition(String.format("$resource/Profile/ServiceName/text() eq '%s'",serviceName));
query.setResult("$resource/Profile/AccessPoint/RunningInstanceInterfaces//Endpoint[@EntryName/string() eq \""+resource+"\"]/text()");
DiscoveryClient<String> client = client();
List<String> endpoints = client.submit(query);
if (endpoints == null || endpoints.isEmpty())
throw new Exception("Cannot retrieve the GCoreEndpoint serviceName: "+serviceName +", serviceClass: " +serviceClass +", in scope: "+context);
String basePath = endpoints.get(0);
if(basePath==null)
throw new Exception("Endpoint:"+resource+", is null for serviceName: "+serviceName +", serviceClass: " +serviceClass +", in scope: "+context);
return basePath;
}
private static void sendEmail(String basePath, String messageToEditor) {
try(CloseableHttpClient client = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();){
String subject = "TEST: just a test of email notification";
// send email to the editor
logger.info("The message that is going to be send to the editor is\n" + messageToEditor);
String postRequestURL = basePath + SOCIAL_SEND_EMAIL + "?gcube-token=" + token;
logger.info("The post URL is {}",postRequestURL);
HttpPost postRequest = new HttpPost(postRequestURL);
JSONObject reqMessage = new JSONObject();
reqMessage.put("subject", subject);
reqMessage.put("body", messageToEditor);
JSONArray recipients = new JSONArray();
JSONObject recipient = new JSONObject();
recipient.put("id", username);
recipients.add(recipient);
reqMessage.put("recipients", recipients);
StringEntity input = new StringEntity(reqMessage.toJSONString());
input.setContentType(MEDIATYPE_JSON);
postRequest.setEntity(input);
logger.debug("Whole editor message is going to be " + reqMessage.toJSONString());
CloseableHttpResponse response = client.execute(postRequest);
logger.info("The response code is {} ",response.getStatusLine().getStatusCode());
Map<String, Object> mapResponseWritePost = SocialCommunications.getResponseEntityAsJSON(response);
if (response.getStatusLine().getStatusCode() != 201){
logger.error("Failed to send message to editor : HTTP error code : "
+ response.getStatusLine().getStatusCode() + mapResponseWritePost.get("message"));
}
}catch(Exception e){
logger.error("Failed to send messages", e);
}
}
}