minor fixes

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/grsf-manage-widget@163066 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2018-02-08 15:57:52 +00:00
parent 869421bad1
commit cf872c6d87
7 changed files with 67 additions and 55 deletions

View File

@ -35,6 +35,7 @@ import com.github.gwtbootstrap.client.ui.Modal;
import com.github.gwtbootstrap.client.ui.TextArea;
import com.github.gwtbootstrap.client.ui.TextBox;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
import com.github.gwtbootstrap.client.ui.event.HiddenEvent;
import com.github.gwtbootstrap.client.ui.event.HiddenHandler;
import com.google.gwt.core.client.GWT;
@ -203,11 +204,14 @@ public class ManageProductWidget extends Composite{
// async request to fetch the product
retrieveProductBean(productIdentifier);
listenEvents(this.eventBus);
}
/**
* Liste events
* @param eventBus
*/
private void listenEvents(HandlerManager eventBus) {
eventBus.addHandler(EnableConfirmButtonEvent.TYPE, new EnableConfirmButtonEventHandler() {
@ -281,9 +285,7 @@ public class ManageProductWidget extends Composite{
@Override
public void onClick(ClickEvent event) {
eventBus.fireEvent(new EnableConfirmButtonEvent());
}
});
@ -319,7 +321,7 @@ public class ManageProductWidget extends Composite{
listBoxStatus.addItem("Select a new status");
listBoxStatus.getElement().<SelectElement>cast().getOptions().getItem(0).setDisabled(true);
for (Status availableStatus : statusToShow) {
listBoxStatus.addItem(availableStatus.toString());
listBoxStatus.addItem(availableStatus.toString(), availableStatus.toString());
}
listBoxStatus.setSelectedIndex(0);
@ -327,9 +329,7 @@ public class ManageProductWidget extends Composite{
@Override
public void onChange(ChangeEvent event) {
eventBus.fireEvent(new EnableConfirmButtonEvent());
}
});
@ -337,9 +337,7 @@ public class ManageProductWidget extends Composite{
@Override
public void onChange(ChangeEvent event) {
eventBus.fireEvent(new EnableConfirmButtonEvent());
}
});
@ -388,17 +386,6 @@ public class ManageProductWidget extends Composite{
String report = "";
Set<String> hashtags = new HashSet<>();
// if the status has not be changed ...
if(listBoxStatus.getSelectedIndex() <= 0){
bean.setNewStatus(bean.getCurrentStatus());
report = "- The Status is unchanged";
}
else{
bean.setNewStatus(Status.fromString(listBoxStatus.getSelectedItemText()));
report = "- The Status has been changed to " + bean.getNewStatus().getOrigName();
hashtags.add(bean.getNewStatus().getOrigName());
}
manageProductModal.setCloseVisible(false);
cancelButton.setEnabled(false);
confirmButton.setEnabled(false);
@ -446,37 +433,52 @@ public class ManageProductWidget extends Composite{
if(!bean.getSimilarGrsfRecords().isEmpty()){
report += "\n- Suggested merges:";
for(SimilarGRSFRecord sR: bean.getSimilarGrsfRecords()){
if(sR.isSuggestedMerge()){
bean.setMergesInvolved(true);
report += "\n\t - merge the current record with record " + sR.getKnowledgeBaseId() + ";";
}
if(bean.isMergesInvolved()){
report += "\n- The update involves a merge operation.";
hashtags.add(HashTagsOnUpdate.MERGE.getString());
}
}
if(bean.isMergesInvolved()){
report += "\n- The update involves a merge operation;";
hashtags.add(HashTagsOnUpdate.MERGE.getString());
}
}
// set new values
bean.setAnnotation(new HTML(annotationArea.getText().trim()).getText());
if(bean.getAnnotation() != null && !bean.getAnnotation().isEmpty())
report += "\n- Annotation message is: " + bean.getAnnotation();
report += "\n- Annotation message is: " + bean.getAnnotation() + ";";
// traceability flag
Boolean traceabilityNewValue = traceabilityFlag.getValue();
boolean currentTraceabilitFlag = bean.isTraceabilityFlag();
if(!traceabilityNewValue.equals(currentTraceabilitFlag)){
report += "\n- Traceability flag has been changed to: " + traceabilityNewValue;
report += "\n- Traceability flag has been changed to: '" + traceabilityNewValue + "';";
if(traceabilityNewValue)
hashtags.add(HashTagsOnUpdate.TRACEABILITY_FLAG_SET.getString());
else
hashtags.add(HashTagsOnUpdate.TRACEABILITY_FLAG_UNSET.getString());
}
// update the traceability flag
bean.setTraceabilityFlag(traceabilityNewValue);
// force the new status in the listbox
if(bean.isMergesInvolved()){
bean.setNewStatus(Status.To_be_Merged);
report += "\n- The Status has been changed to '" + bean.getNewStatus().getOrigName() + "'.";
}
else if(listBoxStatus.getSelectedIndex() <= 0){
// if the status has not be changed ...
bean.setNewStatus(bean.getCurrentStatus());
report += "\n- The Status is unchanged.";
}
else{
bean.setNewStatus(Status.fromString(listBoxStatus.getSelectedItemText()));
report += "\n- The Status has been changed to '" + bean.getNewStatus().getOrigName() + "'.";
hashtags.add(bean.getNewStatus().getOrigName());
}
// set the report
bean.setReport(report);
@ -496,6 +498,8 @@ public class ManageProductWidget extends Composite{
formUpdate.setVisible(false);
manageProductModal.setCloseVisible(true);
cancelButton.setEnabled(true);
cancelButton.setText("Ok");
cancelButton.setType(ButtonType.INFO);
loaderIcon.setVisible(false);
updateSucceeded = true;
}

View File

@ -13,6 +13,7 @@ import com.github.gwtbootstrap.client.ui.Image;
import com.github.gwtbootstrap.client.ui.Modal;
import com.github.gwtbootstrap.client.ui.TextArea;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.FontWeight;
import com.google.gwt.dom.client.Style.Unit;
@ -94,7 +95,7 @@ public class ManageRevertOperationWidget extends Composite {
revertOperationModal.addStyleName("management-metadata-modal-style");
// revertOperationModal.getElement().getStyle().setWidth(60, Unit.PCT);
revertOperationModal.show();
loaderIcon.getElement().getStyle().setMarginRight(10, Unit.PX);
moreInfoAboutOperation.getElement().getStyle().setMarginBottom(50, Unit.PX);
// async request to fetch the product
@ -152,7 +153,8 @@ public class ManageRevertOperationWidget extends Composite {
loaderIcon.setVisible(true);
revertButton.setEnabled(false);
cancelButton.setEnabled(false);
service.performRevertOperation(revertableOperation, new AsyncCallback<Boolean>() {
@Override
@ -168,7 +170,9 @@ public class ManageRevertOperationWidget extends Composite {
infoBlock.setType(AlertType.SUCCESS);
infoBlock.setText("The request has been processed successfully!");
revertButton.removeFromParent();
cancelButton.removeFromParent();
cancelButton.setText("Ok");
cancelButton.setType(ButtonType.INFO);
cancelButton.setEnabled(true);
}
}

View File

@ -434,7 +434,13 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
throw new Exception("This operation can no longer be reverted (link expired)!");
DataCatalogue catalogue = getCatalogue(context);
String recordUrl = catalogue.getDataset(uuid, catalogue.getApiKeyFromUsername(username)).getExtrasAsHashMap().get(Constants.ITEM_URL_FIELD);
Map<String, String> extras = catalogue.getDataset(uuid, catalogue.getApiKeyFromUsername(username)).getExtrasAsHashMap();
String recordUrl = extras.get(Constants.ITEM_URL_FIELD);
String currentStatus = extras.get(Constants.STATUS_OF_THE_GRSF_RECORD_CUSTOM_KEY);
// check current record status
if(!currentStatus.equals(Status.To_be_Merged.getOrigName()))
throw new Exception("This record is no longer involved in a merge operation!");
// check if it is a reviewer, than he can do what he wants (no matter the admin)
if(isReviewer){
@ -522,7 +528,7 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
private boolean isReviewer(String username, List<GCubeTeam> teamRolesByUser){
for (GCubeTeam team : teamRolesByUser) {
if(team.getTeamName().equals(team.getTeamName().equals(Constants.GRSF_CATALOGUE_REVIEWER_ROLE))){
if(team.getTeamName().equals(Constants.GRSF_CATALOGUE_REVIEWER_ROLE)){
logger.info("User " + username + " is allowed to modify GRSF records as reviewer");
return true;
}

View File

@ -18,7 +18,7 @@ public class RevertOperationUrl {
private static final Logger logger = LoggerFactory.getLogger(RevertOperationUrl.class);
// parameters for reverting operations
public static final String MANAGE_QUERY_PARAM = "manage=true&";
public static final String MANAGE_QUERY_PARAM = "manage=true";
public static final String ADMIN_QUERY_PARAM = "admin";
public static final String TIMESTAMP_QUERY_PARAM = "t";
public static final String UUID_QUERY_PARAM = "uuid";
@ -49,7 +49,7 @@ public class RevertOperationUrl {
}
/**
* Build a crypted, encoded and shortened url
* Build an encrypted, encoded and shortened url
* @return
* @throws Exception
*/
@ -59,8 +59,9 @@ public class RevertOperationUrl {
logger.info("Query is " + query);
String encryptedQuery = StringEncrypter.getEncrypter().encrypt(query);
encryptedQuery = URLEncoder.encode(encryptedQuery, "UTF-8");
logger.debug("Encrypted part looks like " + encryptedQuery);
String encryptedUrl =
baseUrl
baseUrl + "?"
+ MANAGE_QUERY_PARAM + "&"
+ encryptedQuery;
UrlShortener shortener = new UrlShortener();
@ -91,8 +92,7 @@ public class RevertOperationUrl {
String decoded = URLDecoder.decode(params, "UTF-8");
String decrypted = StringEncrypter.getEncrypter().decrypt(decoded);
logger.info("Decrypted is " + decrypted);
logger.debug("Decrypted part looks like " + decrypted);
try{
String[] splittedQuery = decrypted.split("&");
@ -113,7 +113,7 @@ public class RevertOperationUrl {
this.uuid = value;
break;
case OPERATION_REVERT_QUERY_PARAM:
this.operation = RevertableOperations.valueOf(value);
this.operation = RevertableOperations.valueOf(value.toUpperCase());
break;
default:
break;
@ -126,7 +126,7 @@ public class RevertOperationUrl {
}
public boolean isTimestampValid() {
return TTL + this.timestamp < System.currentTimeMillis();
return (TTL + this.timestamp) > System.currentTimeMillis();
}
public String getBaseUrl() {

View File

@ -89,7 +89,7 @@ public class SocialCommunications {
+ "<br>a revert operation (undo merge) has been requested on record RECORD_URL, by ADMIN_WHO_CHANGED.";
private static final String EMAIL_EDITOR_REVERT = "Dear ORIGINAL_USER,"
+"<br> a revert operation (undo merge) has been requested on this RECORD_URL you managed by ADMIN_WHO_CHANGED.";
+"<br>a revert operation (undo merge) has been requested on this RECORD_URL you managed by ADMIN_WHO_CHANGED.";
// post on revert
private static final String POST_ON_REVERT = "Dear members,"
@ -169,7 +169,6 @@ public class SocialCommunications {
// ask token application
HttpPost postRequest = new HttpPost(basePath + SOCIAL_SERVICE_APPLICATION_TOKEN + "?gcube-token=" + tokenUser);
JSONObject requestToken = new JSONObject();
// requestToken.put("app_id", APPLICATION_ID_CATALOGUE_MANAGER.split("\\.")[APPLICATION_ID_CATALOGUE_MANAGER.split("\\.").length - 1]); // TODO
requestToken.put("app_id", APPLICATION_ID_CATALOGUE_MANAGER);
StringEntity input = new StringEntity(requestToken.toJSONString());
input.setContentType(MEDIATYPE_JSON);
@ -528,6 +527,9 @@ public class SocialCommunications {
String messageToReviewer = EMAIL_REVIEWER_REVERT.replace("ADMIN_WHO_CHANGED", rInfo.getFullNameCurrentAdmin()).replace("RECORD_URL", rInfo.getRecordUrl()).
replace("ORIGINAL_USER", rInfo.getFullNameOriginalAdmin());
String subject = "Revert merge request on GRSF Record";
messageToEditor = messageToEditor.replace("<br>", "\n");
messageToReviewer = messageToReviewer.replace("<br>", "\n");
// send email to the editor
logger.info("The message that is going to be send to the editor is\n" + messageToEditor);

View File

@ -139,8 +139,6 @@ public class Utils {
toReturn.put(replacedKey, values);
}
return toReturn;
}
@ -268,7 +266,7 @@ public class Utils {
try{
// write post about this
SocialCommunications.writePostOnRevert(baseUrlSocial, rInfo, true);
SocialCommunications.writePostOnRevert(baseUrlSocial, rInfo, false);
// alert who's involved
SocialCommunications.sendEmailAdministratorsOnOperationReverted(baseUrlSocial, rInfo, groupId);
@ -301,18 +299,14 @@ public class Utils {
for(SimilarGRSFRecord s: bean.getSimilarGrsfRecords()){
if(s.isSuggestedMerge()){
String productId = s.getKnowledgeBaseId();
Map<String, List<String>> extrasMap = getExtrasAsHashMap(catalogue.getDataset(productId, sysApi).getExtras());
extrasMap.put(Constants.STATUS_OF_THE_GRSF_RECORD_CUSTOM_KEY, Arrays.asList(Status.To_be_Merged.getOrigName()));
catalogue.patchProductCustomFields(productId, sysApi, extrasMap);
// CkanDataset dataset = catalogue.getDataset(productId, sysApi);
// Map<String, List<String>> extrasMap = getExtrasAsHashMap(dataset.getExtras());
Map<String, List<String>> updateStatus = new HashMap<String, List<String>>(1);
updateStatus.put(Constants.STATUS_OF_THE_GRSF_RECORD_CUSTOM_KEY, Arrays.asList(Status.To_be_Merged.getOrigName()));
catalogue.patchProductCustomFields(productId, sysApi, updateStatus, true);
}
}
// update the current status record
String productId = bean.getKnowledgeBaseId();
Map<String, List<String>> extrasMap = getExtrasAsHashMap(catalogue.getDataset(productId, sysApi).getExtras());
extrasMap.put(Constants.STATUS_OF_THE_GRSF_RECORD_CUSTOM_KEY, Arrays.asList(Status.To_be_Merged.getOrigName()));
catalogue.patchProductCustomFields(productId, sysApi, extrasMap);
}
/**

View File

@ -29,8 +29,10 @@ public class RevertableOperationInfo implements Serializable{
this.fullNameCurrentAdmin = fullNameCurrentAdmin;
this.uuid = uuid;
this.fullNameOriginalAdmin = fullNameOriginalAdmin;
this.userNameOriginalAdmin = userNameOriginalAdmin;
this.timestamp = timestamp;
this.operation = operation;
}
public long getTimestamp() {