improved generic resource usage

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/grsf-manage-widget@142777 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2017-02-20 15:16:57 +00:00
parent 8a3110e337
commit e24efc16f6
5 changed files with 104 additions and 144 deletions

View File

@ -30,7 +30,7 @@ public class FormEntryModel extends Composite{
public FormEntryModel(String label, String value) { public FormEntryModel(String label, String value) {
initWidget(uiBinder.createAndBindUi(this)); initWidget(uiBinder.createAndBindUi(this));
labelEntry.add(new HTML("<b>" + label + "</b>")); labelEntry.add(new HTML("<b>Item " + label + ":</b>"));
entryValue.setText(value); entryValue.setText(value);
} }

View File

@ -55,21 +55,21 @@ public class ManageProductWidget extends Composite{
@UiField @UiField
TextArea titleTextArea; TextArea titleTextArea;
@UiField // @UiField
TextBox productType; // TextBox productType;
@UiField
TextBox productGrsfType;
@UiField
TextBox productSemanticId;
@UiField
TextBox productShortTitle;
@UiField @UiField
TextBox productSource; TextBox productGrsfType;
// @UiField
// TextBox productSemanticId;
//
// @UiField
// TextBox productShortTitle;
//
// @UiField
// TextBox productSource;
@UiField @UiField
TextBox currentStatus; TextBox currentStatus;
@ -91,12 +91,12 @@ public class ManageProductWidget extends Composite{
@UiField @UiField
ControlGroup listBoxStatusGroup; ControlGroup listBoxStatusGroup;
@UiField @UiField
ControlGroup annotationAreaGroup; ControlGroup annotationAreaGroup;
@UiField @UiField
ControlGroup productTypeGroup; ControlGroup productGrsfTypeGroup;
@UiField @UiField
Form formUpdate; Form formUpdate;
@ -130,7 +130,7 @@ public class ManageProductWidget extends Composite{
loadingImage.setVisible(true); loadingImage.setVisible(true);
manageProductModal.show(); manageProductModal.show();
// async request to fetch the product // async request to fetch the product
retrieveProductBean(productIdentifier); retrieveProductBean(productIdentifier);
} }
@ -144,9 +144,9 @@ public class ManageProductWidget extends Composite{
public void onSuccess(Boolean result) { public void onSuccess(Boolean result) {
if(!result){ if(!result){
showInfo(NO_ADMIN_ROLE, AlertType.ERROR); showInfo(NO_ADMIN_ROLE, AlertType.ERROR);
// hide the form and disable the send button // hide the form and disable the send button
formUpdate.setVisible(false); formUpdate.setVisible(false);
confirmButton.setEnabled(false); confirmButton.setEnabled(false);
@ -162,19 +162,19 @@ public class ManageProductWidget extends Composite{
bean = result; bean = result;
annotationArea.setText(""); annotationArea.setText("");
infoBlock.setVisible(false); infoBlock.setVisible(false);
titleTextArea.setText(bean.getItemTitle()); titleTextArea.setText(bean.getItemTitle());
currentStatus.setText(bean.getCurrentStatus().toString()); currentStatus.setText(bean.getCurrentStatus().toString());
productGrsfType.setText(bean.getGrsfType()); productGrsfType.setText(bean.getGrsfType());
productType.setText(bean.getType()); // productType.setText(bean.getType());
productSemanticId.setText(bean.getSemanticId()); // productSemanticId.setText(bean.getSemanticId());
productShortTitle.setText(bean.getShortTitle()); // productShortTitle.setText(bean.getShortTitle());
productSource.setText(bean.getSource()); // productSource.setText(bean.getSource());
// check if we need to show more // check if we need to show more
if(bean.getExtrasIfAvailable() != null && !bean.getExtrasIfAvailable().isEmpty()) if(bean.getExtrasIfAvailable() != null && !bean.getExtrasIfAvailable().isEmpty())
addExtrasAfter(bean, productTypeGroup); addExtrasAfter(bean, productGrsfTypeGroup);
List<GRSFStatus> statusToShow = new ArrayList<GRSFStatus>(STATUS); List<GRSFStatus> statusToShow = new ArrayList<GRSFStatus>(STATUS);
statusToShow.remove(bean.getCurrentStatus()); statusToShow.remove(bean.getCurrentStatus());
listBoxStatus.addItem("Select the new status"); listBoxStatus.addItem("Select the new status");
@ -213,9 +213,9 @@ public class ManageProductWidget extends Composite{
@Override @Override
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
showInfo(NO_ADMIN_ROLE, AlertType.ERROR); showInfo(NO_ADMIN_ROLE, AlertType.ERROR);
// hide the form and disable the send button // hide the form and disable the send button
formUpdate.setVisible(false); formUpdate.setVisible(false);
confirmButton.setEnabled(false); confirmButton.setEnabled(false);
@ -225,7 +225,7 @@ public class ManageProductWidget extends Composite{
}); });
} }
/** /**
* Add extras if available after controlGroupBefore * Add extras if available after controlGroupBefore
* @param bean * @param bean
@ -233,20 +233,20 @@ public class ManageProductWidget extends Composite{
*/ */
private void addExtrasAfter(ManageProductBean bean, private void addExtrasAfter(ManageProductBean bean,
ControlGroup controlGroupBefore) { ControlGroup controlGroupBefore) {
int index = formUpdate.getWidgetIndex(controlGroupBefore); int index = formUpdate.getWidgetIndex(controlGroupBefore);
Map<String, String> extras = bean.getExtrasIfAvailable(); Map<String, String> extras = bean.getExtrasIfAvailable();
Iterator<Entry<String, String>> iterator = extras.entrySet().iterator(); Iterator<Entry<String, String>> iterator = extras.entrySet().iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
Map.Entry<java.lang.String, java.lang.String> entry = (Map.Entry<java.lang.String, java.lang.String>) iterator Map.Entry<java.lang.String, java.lang.String> entry = (Map.Entry<java.lang.String, java.lang.String>) iterator
.next(); .next();
formUpdate.insert(new FormEntryModel(entry.getKey(), entry.getValue()), index); formUpdate.insert(new FormEntryModel(entry.getKey(), entry.getValue()), index);
index++; index++;
} }
} }
@UiHandler("cancelButton") @UiHandler("cancelButton")
@ -266,9 +266,9 @@ public class ManageProductWidget extends Composite{
listBoxStatusGroup.setType(ControlGroupType.ERROR); listBoxStatusGroup.setType(ControlGroupType.ERROR);
return; return;
} }
annotationAreaGroup.setType(ControlGroupType.NONE); annotationAreaGroup.setType(ControlGroupType.NONE);
if(annotationArea.getText() == null || annotationArea.getText().isEmpty()){ if(annotationArea.getText() == null || annotationArea.getText().isEmpty()){
annotationArea.setPlaceholder("An annotation message to send along the update (mandatory)"); annotationArea.setPlaceholder("An annotation message to send along the update (mandatory)");
annotationAreaGroup.setType(ControlGroupType.ERROR); annotationAreaGroup.setType(ControlGroupType.ERROR);

View File

@ -44,45 +44,45 @@
</b:Controls> </b:Controls>
</b:ControlGroup> </b:ControlGroup>
<b:ControlGroup ui:field="productSemanticIdGroup"> <!-- <b:ControlGroup ui:field="productSemanticIdGroup"> -->
<b:ControlLabel for="productSemanticId" title="The semantic id"> <!-- <b:ControlLabel for="productSemanticId" title="The semantic id"> -->
<b>Item Semantic Id:</b> <!-- <b>Item Semantic Id:</b> -->
</b:ControlLabel> <!-- </b:ControlLabel> -->
<b:Controls> <!-- <b:Controls> -->
<b:TextBox b:id="productSemanticId" alternateSize="LARGE" <!-- <b:TextBox b:id="productSemanticId" alternateSize="LARGE" -->
width="97%" title="The semantic id" enabled="false" ui:field="productSemanticId"></b:TextBox> <!-- width="97%" title="The semantic id" enabled="false" ui:field="productSemanticId"></b:TextBox> -->
</b:Controls> <!-- </b:Controls> -->
</b:ControlGroup> <!-- </b:ControlGroup> -->
<b:ControlGroup ui:field="productShortTitleGroup"> <!-- <b:ControlGroup ui:field="productShortTitleGroup"> -->
<b:ControlLabel for="productShortTitle" title="The short title"> <!-- <b:ControlLabel for="productShortTitle" title="The short title"> -->
<b>Item Short Title:</b> <!-- <b>Item Short Title:</b> -->
</b:ControlLabel> <!-- </b:ControlLabel> -->
<b:Controls> <!-- <b:Controls> -->
<b:TextBox b:id="productShortTitle" alternateSize="LARGE" <!-- <b:TextBox b:id="productShortTitle" alternateSize="LARGE" -->
width="97%" title="The short title" enabled="false" ui:field="productShortTitle"></b:TextBox> <!-- width="97%" title="The short title" enabled="false" ui:field="productShortTitle"></b:TextBox> -->
</b:Controls> <!-- </b:Controls> -->
</b:ControlGroup> <!-- </b:ControlGroup> -->
<b:ControlGroup ui:field="productSourceGroup"> <!-- <b:ControlGroup ui:field="productSourceGroup"> -->
<b:ControlLabel for="productSource" title="The sources"> <!-- <b:ControlLabel for="productSource" title="The sources"> -->
<b>Item Sources:</b> <!-- <b>Item Sources:</b> -->
</b:ControlLabel> <!-- </b:ControlLabel> -->
<b:Controls> <!-- <b:Controls> -->
<b:TextBox b:id="productSource" alternateSize="LARGE" <!-- <b:TextBox b:id="productSource" alternateSize="LARGE" -->
width="97%" title="The sources" enabled="false" ui:field="productSource"></b:TextBox> <!-- width="97%" title="The sources" enabled="false" ui:field="productSource"></b:TextBox> -->
</b:Controls> <!-- </b:Controls> -->
</b:ControlGroup> <!-- </b:ControlGroup> -->
<b:ControlGroup ui:field="productTypeGroup"> <!-- <b:ControlGroup ui:field="productTypeGroup"> -->
<b:ControlLabel for="productType" title="The Item type"> <!-- <b:ControlLabel for="productType" title="The Item type"> -->
<b>Item Type:</b> <!-- <b>Item Type:</b> -->
</b:ControlLabel> <!-- </b:ControlLabel> -->
<b:Controls> <!-- <b:Controls> -->
<b:TextBox b:id="productType" alternateSize="LARGE" <!-- <b:TextBox b:id="productType" alternateSize="LARGE" -->
width="97%" title="The Item type" enabled="false" ui:field="productType"></b:TextBox> <!-- width="97%" title="The Item type" enabled="false" ui:field="productType"></b:TextBox> -->
</b:Controls> <!-- </b:Controls> -->
</b:ControlGroup> <!-- </b:ControlGroup> -->
<b:ControlGroup ui:field="currentStatusGroup"> <b:ControlGroup ui:field="currentStatusGroup">
<b:ControlLabel for="currentStatus" <b:ControlLabel for="currentStatus"

View File

@ -66,10 +66,10 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
// info of the record to be shown at client-side // info of the record to be shown at client-side
private static final String STATUS_CUSTOM_FIELD_KEY = "Status"; private static final String STATUS_CUSTOM_FIELD_KEY = "Status";
private static final String KB_UUID_FIELD_KEY = "UUID Knowledge Base"; private static final String KB_UUID_FIELD_KEY = "UUID Knowledge Base";
private static final String TYPE_FIELD_KEY = "Type"; // private static final String TYPE_FIELD_KEY = "Type";
private static final String GRSF_TYPE_FIELD_KEY = "GRSF type"; private static final String GRSF_TYPE_FIELD_KEY = "GRSF type";
private static final String SHORT_TITLE_FIELD_KEY = "Short Title"; // private static final String SHORT_TITLE_FIELD_KEY = "Short Title";
private static final String SOURCES_TITLE_FIELD_KEY = "Source"; // private static final String SOURCES_TITLE_FIELD_KEY = "Source";
// request post fields FORTH Service // request post fields FORTH Service
private static final String CATALOGUE_ID = "catalog_id"; private static final String CATALOGUE_ID = "catalog_id";
@ -157,7 +157,7 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
else{ else{
toReturn = new ManageProductBean(); toReturn = new ManageProductBean();
// check it is a grsf item, else.. // check it is a grsf item, else..
List<CkanGroup> groups = product.getGroups(); List<CkanGroup> groups = product.getGroups();
boolean isGrsf = false; boolean isGrsf = false;
@ -177,13 +177,13 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
Map<String, String> extras = product.getExtrasAsHashMap(); Map<String, String> extras = product.getExtrasAsHashMap();
String status = extras.get(STATUS_CUSTOM_FIELD_KEY); String status = extras.get(STATUS_CUSTOM_FIELD_KEY);
String uuidKB = extras.get(KB_UUID_FIELD_KEY); String uuidKB = extras.get(KB_UUID_FIELD_KEY);
String productType = extras.get(TYPE_FIELD_KEY); // String productType = extras.get(TYPE_FIELD_KEY);
String productGRSFType = extras.get(GRSF_TYPE_FIELD_KEY); String productGRSFType = extras.get(GRSF_TYPE_FIELD_KEY);
String semanticId = extras.get(productGRSFType + " id"); // i.e "Stock id" or "Fishery id" // String semanticId = extras.get(productGRSFType + " id"); // i.e "Stock id" or "Fishery id"
String shortTitle = extras.get(SHORT_TITLE_FIELD_KEY); // String shortTitle = extras.get(SHORT_TITLE_FIELD_KEY);
String sources = extras.get(SOURCES_TITLE_FIELD_KEY); // String sources = extras.get(SOURCES_TITLE_FIELD_KEY);
String title = product.getTitle(); String title = product.getTitle();
// fetch extras // fetch extras
GenericResourceReaderExtras entries = new GenericResourceReaderExtras(); GenericResourceReaderExtras entries = new GenericResourceReaderExtras();
Set<String> extrasToShow = entries.getLookedUpExtrasKeys(); Set<String> extrasToShow = entries.getLookedUpExtrasKeys();
@ -199,17 +199,17 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
if(status == null || uuidKB == null) if(status == null || uuidKB == null)
throw new Exception("Some information is missing in this record: Status = " + status + ", knowledge_base_uuid = " + uuidKB + throw new Exception("Some information is missing in this record: Status = " + status + ", knowledge_base_uuid = " + uuidKB +
", and grsf type is = " + productType); ", and grsf type is = " + productGRSFType);
toReturn.setCatalogueIdentifier(productIdentifier); toReturn.setCatalogueIdentifier(productIdentifier);
toReturn.setCurrentStatus(GRSFStatus.fromString(status)); toReturn.setCurrentStatus(GRSFStatus.fromString(status));
toReturn.setKnowledgeBaseIdentifier(uuidKB); toReturn.setKnowledgeBaseIdentifier(uuidKB);
toReturn.setItemTitle(title); toReturn.setItemTitle(title);
toReturn.setGrsfType(productGRSFType); toReturn.setGrsfType(productGRSFType);
toReturn.setType(productType); // toReturn.setType(productType);
toReturn.setSemanticId(semanticId); // toReturn.setSemanticId(semanticId);
toReturn.setShortTitle(shortTitle); // toReturn.setShortTitle(shortTitle);
toReturn.setSource(sources); // toReturn.setSource(sources);
logger.info("Returning item bean " + toReturn); logger.info("Returning item bean " + toReturn);

View File

@ -11,13 +11,13 @@ public class ManageProductBean implements Serializable{
private static final long serialVersionUID = -4882608487467259326L; private static final long serialVersionUID = -4882608487467259326L;
private String itemTitle; private String itemTitle;
private String semanticId; // Stock id or Fishery id // private String semanticId; // Stock id or Fishery id
private String shortTitle; // private String shortTitle;
private String catalogueIdentifier; private String catalogueIdentifier;
private String knowledgeBaseIdentifier; private String knowledgeBaseIdentifier;
private String type; // Fishery or Stock type (e.g., Assessment_Unit, Marine Resource and so on) // private String type; // Fishery or Stock type (e.g., Assessment_Unit, Marine Resource and so on)
private String grsfType; // fishery/stock private String grsfType; // fishery/stock
private String source; // the current source // private String source; // the current source
private Map<String, String> extrasIfAvailable; private Map<String, String> extrasIfAvailable;
// info that could change // info that could change
@ -31,38 +31,31 @@ public class ManageProductBean implements Serializable{
/** /**
* @param itemTitle * @param itemTitle
* @param semanticId
* @param shortTitle
* @param catalogueIdentifier * @param catalogueIdentifier
* @param knowledgeBaseIdentifier * @param knowledgeBaseIdentifier
* @param type
* @param grsfType * @param grsfType
* @param source
* @param extrasIfAvailable * @param extrasIfAvailable
* @param currentStatus * @param currentStatus
* @param newStatus * @param newStatus
* @param annotation * @param annotation
*/ */
public ManageProductBean(String itemTitle, String semanticId, public ManageProductBean(String itemTitle, String catalogueIdentifier,
String shortTitle, String catalogueIdentifier, String knowledgeBaseIdentifier, String grsfType,
String knowledgeBaseIdentifier, String type, String grsfType, Map<String, String> extrasIfAvailable, GRSFStatus currentStatus,
String source, Map<String, String> extrasIfAvailable, GRSFStatus newStatus, String annotation) {
GRSFStatus currentStatus, GRSFStatus newStatus, String annotation) {
super(); super();
this.itemTitle = itemTitle; this.itemTitle = itemTitle;
this.semanticId = semanticId;
this.shortTitle = shortTitle;
this.catalogueIdentifier = catalogueIdentifier; this.catalogueIdentifier = catalogueIdentifier;
this.knowledgeBaseIdentifier = knowledgeBaseIdentifier; this.knowledgeBaseIdentifier = knowledgeBaseIdentifier;
this.type = type;
this.grsfType = grsfType; this.grsfType = grsfType;
this.source = source;
this.extrasIfAvailable = extrasIfAvailable; this.extrasIfAvailable = extrasIfAvailable;
this.currentStatus = currentStatus; this.currentStatus = currentStatus;
this.newStatus = newStatus; this.newStatus = newStatus;
this.annotation = annotation; this.annotation = annotation;
} }
public String getCatalogueIdentifier() { public String getCatalogueIdentifier() {
return catalogueIdentifier; return catalogueIdentifier;
} }
@ -110,14 +103,6 @@ public class ManageProductBean implements Serializable{
this.itemTitle = itemTitle; this.itemTitle = itemTitle;
} }
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getGrsfType() { public String getGrsfType() {
return grsfType; return grsfType;
} }
@ -126,30 +111,6 @@ public class ManageProductBean implements Serializable{
this.grsfType = grsfType; this.grsfType = grsfType;
} }
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public String getSemanticId() {
return semanticId;
}
public void setSemanticId(String semanticId) {
this.semanticId = semanticId;
}
public String getShortTitle() {
return shortTitle;
}
public void setShortTitle(String shortTitle) {
this.shortTitle = shortTitle;
}
public Map<String, String> getExtrasIfAvailable() { public Map<String, String> getExtrasIfAvailable() {
return extrasIfAvailable; return extrasIfAvailable;
} }
@ -160,14 +121,13 @@ public class ManageProductBean implements Serializable{
@Override @Override
public String toString() { public String toString() {
return "ManageProductBean [itemTitle=" + itemTitle + ", semanticId=" return "ManageProductBean [itemTitle=" + itemTitle
+ semanticId + ", shortTitle=" + shortTitle
+ ", catalogueIdentifier=" + catalogueIdentifier + ", catalogueIdentifier=" + catalogueIdentifier
+ ", knowledgeBaseIdentifier=" + knowledgeBaseIdentifier + ", knowledgeBaseIdentifier=" + knowledgeBaseIdentifier
+ ", type=" + type + ", grsfType=" + grsfType + ", source=" + ", grsfType=" + grsfType + ", extrasIfAvailable="
+ source + ", extrasIfAvailable=" + extrasIfAvailable + extrasIfAvailable + ", currentStatus=" + currentStatus
+ ", currentStatus=" + currentStatus + ", newStatus=" + ", newStatus=" + newStatus + ", annotation=" + annotation
+ newStatus + ", annotation=" + annotation + "]"; + "]";
} }
} }