added sdg management, grsf type can be changed. Semantic identifier is reported for connected records and records to be merge. Width and height of the panel have been increased.

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/grsf-manage-widget@164586 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2018-02-26 18:44:59 +00:00
parent fc9650fb4e
commit a34fd17b74
10 changed files with 167 additions and 34 deletions

View File

@ -6,7 +6,10 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.gcube.datacatalogue.common.enums.Fishery_Type;
import org.gcube.datacatalogue.common.enums.Product_Type;
import org.gcube.datacatalogue.common.enums.Status;
import org.gcube.datacatalogue.common.enums.Stock_Type;
import org.gcube.datacatalogue.grsf_manage_widget.client.GRSFManageWidgetService;
import org.gcube.datacatalogue.grsf_manage_widget.client.GRSFManageWidgetServiceAsync;
import org.gcube.datacatalogue.grsf_manage_widget.client.events.EnableConfirmButtonEvent;
@ -39,6 +42,7 @@ 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;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.SelectElement;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ChangeEvent;
@ -84,10 +88,13 @@ public class ManageProductWidget extends Composite{
TextArea shortNameTextBox;
@UiField
TextBox productGrsfType;
ListBox productGrsfTypeListbox;
@UiField
CheckBox traceabilityFlag;
@UiField
CheckBox sdgFlag;
@UiField
TextArea GRSFNameTexBox;
@ -189,7 +196,7 @@ public class ManageProductWidget extends Composite{
// show modal
manageProductModal.addStyleName("management-metadata-modal-style");
// manageProductModal.getElement().getStyle().setWidth(60, Unit.PCT);
((Element)manageProductModal.getElement().getChildNodes().getItem(1)).addClassName("modal-body-custom");
manageProductModal.show();
manageProductModal.addHiddenHandler(new HiddenHandler() {
@ -275,12 +282,31 @@ public class ManageProductWidget extends Composite{
});
semanticIdentifierTextBox.setText(bean.getSemanticIdentifier());
productGrsfType.setText(bean.getGrsfType());
// update product type listbox.. get the available types for the record under management
List<String> types = getTypesForRecord(bean.getDomain());
productGrsfTypeListbox.addItem(bean.getCurrentGrsfType(), bean.getCurrentGrsfType());
for (String type : types) {
productGrsfTypeListbox.addItem(type, type);
}
//select the current
productGrsfTypeListbox.setSelectedValue(bean.getCurrentGrsfType());
productGrsfTypeListbox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
eventBus.fireEvent(new EnableConfirmButtonEvent());
}
});
currentStatus.setText(bean.getCurrentStatus().toString());
// traceability flag
traceabilityFlag.setValue(bean.isTraceabilityFlag());
traceabilityFlag.setText("Traceability");
traceabilityFlag.setTitle("Current value for this flag in the Knowledge Base is " + bean.isTraceabilityFlag());
traceabilityFlag.setTitle("Current value for this flag is " + bean.isTraceabilityFlag());
traceabilityFlag.addClickHandler(new ClickHandler() {
@Override
@ -288,7 +314,19 @@ public class ManageProductWidget extends Composite{
eventBus.fireEvent(new EnableConfirmButtonEvent());
}
});
// sdg flag
sdgFlag.setValue(bean.isSdgFlag());
sdgFlag.setText("Sustainable Development Goals");
sdgFlag.setTitle("Current value for this flag is " + bean.isSdgFlag());
sdgFlag.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
eventBus.fireEvent(new EnableConfirmButtonEvent());
}
});
// manage sources
List<SourceRecord> availableSources = bean.getSources();
panelForSourceItems.add(new SourceWidget(availableSources));
@ -312,7 +350,9 @@ public class ManageProductWidget extends Composite{
// check for new status box
List<Status> statusToShow = new ArrayList<Status>(STATUS);
statusToShow.remove(bean.getCurrentStatus());
statusToShow.remove(Status.To_be_Merged); // it cannot be set by a user
// remove to be merged, since it cannot be set by a user
statusToShow.remove(Status.To_be_Merged);
// if the record isn't approved, then remove also archived
if(!bean.getCurrentStatus().equals(Status.Approved))
@ -395,9 +435,19 @@ public class ManageProductWidget extends Composite{
bean.setShortNameUpdated(shortNameTextBox.getText());
if(!bean.getShortName().equals(bean.getShortNameUpdated())){
report += "\n- The GRSF Short Name has been changed to '" + bean.getShortNameUpdated() + "', from '" + bean.getShortName() + "'";
report += "\n- The GRSF Short Name has been changed to '" + bean.getShortNameUpdated() + "' from '" + bean.getShortName() + "';";
hashtags.add(HashTagsOnUpdate.SHORTNAME_UPDATED.getString());
}
// status
bean.setNewGrsfType(productGrsfTypeListbox.getSelectedItemText());
if(bean.getNewGrsfType().equalsIgnoreCase(bean.getCurrentGrsfType())){
report += "\n- The GRSF Type is unchanged;";
}
else{
report += "\n- The GRSF Type has been changed to '" + bean.getNewGrsfType() + "' from '" + bean.getCurrentGrsfType() + "';";
hashtags.add(HashTagsOnUpdate.GRSF_TYPE_CHANGED.getString());
}
// evaluate the connections and the actions on them
bean.setConnections(connectWidget.getConnectList());
@ -464,6 +514,20 @@ public class ManageProductWidget extends Composite{
// update the traceability flag
bean.setTraceabilityFlag(traceabilityNewValue);
// sdg flag
Boolean sdgNewValue = sdgFlag.getValue();
boolean currentSdgFlag = bean.isSdgFlag();
if(!sdgNewValue.equals(currentSdgFlag)){
report += "\n- SDG flag has been changed to: '" + sdgNewValue + "';";
if(sdgNewValue)
hashtags.add(HashTagsOnUpdate.SDG_FLAG_SET.getString());
else
hashtags.add(HashTagsOnUpdate.SDG_FLAG_UNSET.getString());
}
// update the traceability flag
bean.setSdgFlag(sdgNewValue);
// force the new status in the listbox
if(bean.isMergesInvolved()){
bean.setNewStatus(Status.To_be_Merged);
@ -533,5 +597,17 @@ public class ManageProductWidget extends Composite{
infoBlock.setType(type);
infoBlock.setVisible(true);
}
/**
* Retrieve the list of types for stocks and fisheries, given the domain
* @param domain
* @return a list of types
*/
private List<String> getTypesForRecord(
String domain) {
if(domain == null)
throw new RuntimeException("GRSF Domain is missing!");
return domain.equalsIgnoreCase(Product_Type.FISHERY.getOrigName()) ? Fishery_Type.getTypesAsListString() : Stock_Type.getTypesAsListString();
}
}

View File

@ -58,9 +58,8 @@
<b>GRSF Type:</b>
</b:ControlLabel>
<b:Controls>
<b:TextBox b:id="productGrsfType" alternateSize="LARGE"
placeholder="GRSF Type" width="97%" title="GRSF Type" readOnly="true"
ui:field="productGrsfType"></b:TextBox>
<b:ListBox b:id="productGrsfType" alternateSize="LARGE"
enabled="true" width="97%" title="GRSF Type" ui:field="productGrsfTypeListbox"></b:ListBox>
</b:Controls>
</b:ControlGroup>
@ -131,6 +130,16 @@
</b:Controls>
</b:ControlGroup>
<b:ControlGroup ui:field="sdgFlagGroup">
<b:ControlLabel for="sdgflag" title="SDG Flag">
<b>SDG Flag:</b>
</b:ControlLabel>
<b:Controls>
<b:CheckBox b:id="sdgflag" title="SDG Flag"
ui:field="sdgFlag"></b:CheckBox>
</b:Controls>
</b:ControlGroup>
<b:ControlGroup ui:field="traceabilityFlagGroup">
<b:ControlLabel for="traceabilityflag" title="Traceability Flag">
<b>Traceability Flag:</b>

View File

@ -128,15 +128,15 @@ public class ConnectToWidget extends Composite{
leftPanel.getElement().getStyle().setMarginLeft(20, Unit.PX);
Paragraph name = new Paragraph("Record Name: " + (connected.getTitle() != null? connected.getTitle() : "Unavailable"));
leftPanel.add(name);
Paragraph identifier = new Paragraph("UUID: " +
connected.getKnowledgeBaseId());
leftPanel.add(identifier);
Paragraph semanticIdentifier = new Paragraph("Semantic Identifier: " +
connected.getSemanticIdentifier());
leftPanel.add(semanticIdentifier);
Paragraph identifier = new Paragraph("Record UUID: " +
connected.getKnowledgeBaseId());
leftPanel.add(identifier);
Anchor view = new Anchor();
view.setHref(connected.getUrl());
view.setText("View");
@ -198,7 +198,7 @@ public class ConnectToWidget extends Composite{
VerticalPanel vpLeft = new VerticalPanel();
vpLeft.getElement().getStyle().setMarginLeft(15, Unit.PX);
vpLeft.setWidth("80%");
Paragraph identifier = new Paragraph("Record UUID:");
Paragraph identifier = new Paragraph("UUID:");
// view link
final Anchor view = new Anchor();

View File

@ -130,6 +130,13 @@ public class SimilarGRSFRecordWidget extends Composite {
leftPanel.getElement().getStyle().setMarginLeft(20, Unit.PX);
Paragraph name = new Paragraph("Record Name: " + (similarGRSFRecord.getTitle() != null? similarGRSFRecord.getTitle() : "Unavailable"));
leftPanel.add(name);
Paragraph identifier = new Paragraph("UUID: " +
similarGRSFRecord.getKnowledgeBaseId());
leftPanel.add(identifier);
Paragraph semanticIdentifier = new Paragraph("Semantic Identifier: " +
similarGRSFRecord.getSemanticIdentifier());
leftPanel.add(semanticIdentifier);
if(similarGRSFRecord.getDescription() != null){
String shortDescrption = similarGRSFRecord.getDescription().length() > 45 ?
similarGRSFRecord.getDescription().substring(0, 45) + " ... " :
@ -139,9 +146,6 @@ public class SimilarGRSFRecordWidget extends Composite {
description.setTitle("Description: " + similarGRSFRecord.getDescription());
leftPanel.add(description);
}
Paragraph identifier = new Paragraph("UUID: " +
similarGRSFRecord.getKnowledgeBaseId());
leftPanel.add(identifier);
Anchor view = new Anchor();
view.setHref(similarGRSFRecord.getUrl());

View File

@ -84,6 +84,7 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
if(httpSession.getAttribute(sessionProductKey) != null)
return (ManageProductBean) httpSession.getAttribute(sessionProductKey);
// testing case...
if(!Utils.isIntoPortal()){
Thread.sleep(2000);
@ -116,7 +117,7 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
));
toReturn.setSuggestedByKnowledgeBaseConnections(suggestionsForConnections);
toReturn.setDomain("Stock");
toReturn.setGrsfType("Assessment Unit");
toReturn.setCurrentGrsfType("Assessment Unit");
toReturn.setKnowledgeBaseId("91f1e413-dc9f-3b4e-b1c5-0e8560177253");
toReturn.setShortName("Widow rockfish - US West Coast");
toReturn.setShortNameUpdated("Widow rockfish - US West Coast");
@ -217,7 +218,6 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
// get extras as pairs
List<CkanPair> extrasAsPairs = record.getExtras();
Map<String, List<String>> extrasWithoutNamespaces = Utils.replaceFieldsKey(extrasAsPairs, fieldsNamespacesMap);
String catalogueIdentifier = record.getId();
String description = record.getNotes();
@ -236,6 +236,14 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
logger.warn("Unable to fetch traceability flag. Setting it to false", e);
}
boolean sdgFlag = false;
try{
sdgFlag = extrasWithoutNamespaces.get(Constants.SDG_FLAG_CUSTOM_KEY).get(0).equalsIgnoreCase("true");
}catch(Exception e){
logger.warn("Unable to fetch sdg flag. Setting it to false", e);
}
// TODO, remove
if(status.equals(Status.To_be_Merged) || status.equals(Status.Rejected))
throw new Exception("Records under merging activity or rejected cannot be managed!");
@ -246,7 +254,7 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
if(similarGrsfRecordsAsStrings != null && !similarGrsfRecordsAsStrings.isEmpty()){
if(!similarGrsfRecordsAsStrings.get(0).equals(Constants.NO_SIMILAR_GRSF_RECORDS)){
for (String similarGRSFRecord : similarGrsfRecordsAsStrings) {
similarRecords.add(Utils.similarGRSFRecordFromJson(similarGRSFRecord, catalogue, apiKey));
similarRecords.add(Utils.similarGRSFRecordFromJson(similarGRSFRecord, catalogue, apiKey, httpSession));
}
}
}
@ -299,7 +307,7 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
// set the values
toReturn = new ManageProductBean(
semanticId, catalogueIdentifier, uuidKB, grsfType,
grsfDomain, shortName, description, grsfName,traceabilityFlag,
grsfDomain, shortName, description, grsfName,traceabilityFlag, sdgFlag,
status, recordUrl, sources, similarRecords,
connectedBeans, suggestedConnectionsByKnowledgeBase);

View File

@ -102,6 +102,9 @@ public class GRSFUpdaterServiceClient {
obj.put(Constants.NEW_STATUS, bean.getNewStatus().toString().toLowerCase());
obj.put(Constants.OLD_STATUS, bean.getCurrentStatus().toString().toLowerCase());
obj.put(Constants.TRACEABILITY_FLAG, bean.isTraceabilityFlag());
obj.put(Constants.SDG_FLAG, bean.isSdgFlag());
obj.put(Constants.GRSF_TYPE_OLD, bean.getCurrentGrsfType());
obj.put(Constants.GRSF_TYPE_NEW, bean.getNewGrsfType());
String annotation = bean.getAnnotation() != null ? bean.getAnnotation(): "";
obj.put(Constants.ANNOTATION, annotation.replaceAll("\"", ""));

View File

@ -451,7 +451,7 @@ public class Utils {
* @return {@link SimilarGRSFRecord}
* @throws ParseException
*/
public static SimilarGRSFRecord similarGRSFRecordFromJson(String json, DataCatalogue ctl, String apiKey) throws ParseException{
public static SimilarGRSFRecord similarGRSFRecordFromJson(String json, DataCatalogue ctl, String apiKey, HttpSession httpSession) throws ParseException{
if(json == null)
return null;
@ -461,6 +461,12 @@ public class Utils {
String uuid = getDatasetKnowledgeBaseIdFromUrl((String)object.get(Constants.SIMILAR_RECORDS_BEAN_FIELD_URL));
CkanDataset dataset = ctl.getDataset(uuid, apiKey);
boolean isStock = dataset.getExtrasAsHashMap().get(Constants.DOMAIN_CUSTOM_KEY).contains(Product_Type.STOCK.getOrigName());
Map<String, String> fieldsNamespacesMap =
Utils.getFieldToFieldNameSpaceMapping(httpSession, isStock ?
Constants.GENERIC_RESOURCE_NAME_MAP_KEY_NAMESPACES_STOCK : Constants.GENERIC_RESOURCE_NAME_MAP_KEY_NAMESPACES_FISHERY);
Map<String, List<String>> extrasWithoutNamespaces = Utils.replaceFieldsKey(dataset.getExtras(), fieldsNamespacesMap);
return new SimilarGRSFRecord(
uuid,
@ -468,8 +474,8 @@ public class Utils {
(String)object.get(Constants.SIMILAR_RECORDS_BEAN_FIELD_NAME),
dataset.getTitle(),
(String)object.get(Constants.SIMILAR_RECORDS_BEAN_FIELD_URL),
(String)object.get(Constants.SIMILAR_RECORDS_BEAN_FIELD_IDENTIFIER),
dataset.getExtrasAsHashMap().get(Constants.DOMAIN_CUSTOM_KEY)
extrasWithoutNamespaces.get(Constants.GRSF_SEMANTIC_IDENTIFIER_CUSTOM_KEY).get(0),
extrasWithoutNamespaces.get(Constants.DOMAIN_CUSTOM_KEY).get(0)
);
}

View File

@ -11,7 +11,10 @@ public enum HashTagsOnUpdate {
CONNECT("connect"),
SHORTNAME_UPDATED("shortname_updated"),
TRACEABILITY_FLAG_SET("traceability_flag_set"),
TRACEABILITY_FLAG_UNSET("traceability_flag_unset");
TRACEABILITY_FLAG_UNSET("traceability_flag_unset"),
SDG_FLAG_SET("sdg_flag_set"),
SDG_FLAG_UNSET("sdg_flag_unset"),
GRSF_TYPE_CHANGED("grsf_type_changed");
private String string;

View File

@ -14,9 +14,11 @@ public class ManageProductBean extends GenericRecord{
private static final long serialVersionUID = -4882608487467259326L;
private String catalogueIdentifier; // Catalogue id
private String grsfType; // Fishery or Stock type (e.g., Assessment_Unit, Marine Resource and so on)
private String currentGrsfType; // Fishery or Stock type (e.g., Assessment_Unit, Marine Resource and so on)
private String newGrsfType;
private String shortNameUpdated; // the updated one, if any
private boolean traceabilityFlag; //from false to true etc
private boolean sdgFlag;
private Status currentStatus;
private Status newStatus;
private String annotation; // added by the administrator
@ -44,6 +46,7 @@ public class ManageProductBean extends GenericRecord{
String description,
String title,
boolean traceabilityFlag,
boolean sdgFlag,
Status currentStatus,
String recordUrl,
List<SourceRecord> sources,
@ -53,7 +56,7 @@ public class ManageProductBean extends GenericRecord{
) {
super(knowledgeBaseIdentifier, description, shortName, title, recordUrl, semanticIdentifier, grsfDomain);
this.catalogueIdentifier = catalogueIdentifier;
this.grsfType = grsfType;
this.currentGrsfType = grsfType;
this.shortNameUpdated = shortName;
this.traceabilityFlag = traceabilityFlag;
this.currentStatus = currentStatus;
@ -61,6 +64,7 @@ public class ManageProductBean extends GenericRecord{
this.similarGrsfRecords = similarGrsfRecords;
this.currentConnections = currentConnections;
this.suggestedByKnowledgeBaseConnections = suggestedByKnowledgeBaseConnections;
this.sdgFlag = sdgFlag;
}
public List<SourceRecord> getSources() {
@ -87,12 +91,22 @@ public class ManageProductBean extends GenericRecord{
this.catalogueIdentifier = catalogueIdentifier;
}
public String getGrsfType() {
return grsfType;
public String getCurrentGrsfType() {
return currentGrsfType;
}
public void setGrsfType(String grsfType) {
this.grsfType = grsfType;
public void setCurrentGrsfType(String currentGrsfType) {
this.currentGrsfType = currentGrsfType;
}
public String getNewGrsfType() {
return newGrsfType;
}
public void setNewGrsfType(String newGrsfType) {
this.newGrsfType = newGrsfType;
}
public Status getCurrentStatus() {
@ -193,11 +207,21 @@ public class ManageProductBean extends GenericRecord{
this.hashtags = hashtags;
}
public boolean isSdgFlag() {
return sdgFlag;
}
public void setSdgFlag(boolean sdgFlag) {
this.sdgFlag = sdgFlag;
}
@Override
public String toString() {
return "ManageProductBean [catalogueIdentifier=" + catalogueIdentifier
+ ", grsfType=" + grsfType + ", shortNameUpdated="
+ ", currentGrsfType=" + currentGrsfType + ", newGrsfType=" + newGrsfType +
", shortNameUpdated="
+ shortNameUpdated + ", traceabilityFlag=" + traceabilityFlag
+ ", sdgFlag=" + sdgFlag
+ ", currentStatus=" + currentStatus + ", newStatus="
+ newStatus + ", annotation=" + annotation + ", sources="
+ sources + ", similarGrsfRecords=" + similarGrsfRecords

View File

@ -7,7 +7,7 @@ package org.gcube.datacatalogue.grsf_manage_widget.shared;
public class SourceRecord extends GenericRecord{
private static final long serialVersionUID = -5144710283443577518L;
private String name;
private String name; // one of RAM, FIRMS, FishSource
public SourceRecord() {
super();