The set of information that could be shown now is extensible. A Generic Resource named GRSFManageEntries is looked up to check if extras info need to be shown
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/grsf-manage-widget@142757 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
78d650512c
commit
c05c77ca85
|
@ -0,0 +1,37 @@
|
|||
package org.gcube.datacatalogue.grsf_manage_widget.client.view;
|
||||
|
||||
import com.github.gwtbootstrap.client.ui.ControlLabel;
|
||||
import com.github.gwtbootstrap.client.ui.TextBox;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.uibinder.client.UiBinder;
|
||||
import com.google.gwt.uibinder.client.UiField;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
|
||||
/**
|
||||
* A dynamic ControlGroup to add to a form
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class FormEntryModel extends Composite{
|
||||
|
||||
private static FormEntryModelUiBinder uiBinder = GWT
|
||||
.create(FormEntryModelUiBinder.class);
|
||||
|
||||
interface FormEntryModelUiBinder extends UiBinder<Widget, FormEntryModel> {
|
||||
}
|
||||
|
||||
@UiField
|
||||
ControlLabel labelEntry;
|
||||
|
||||
@UiField
|
||||
TextBox entryValue;
|
||||
|
||||
public FormEntryModel(String label, String value) {
|
||||
initWidget(uiBinder.createAndBindUi(this));
|
||||
labelEntry.add(new HTML("<b>" + label + "</b>"));
|
||||
entryValue.setText(value);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
|
||||
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
|
||||
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
|
||||
<g:HTMLPanel>
|
||||
<b:ControlGroup>
|
||||
<b:ControlLabel for="labelEntry" ui:field="labelEntry">
|
||||
<!-- Label goes here -->
|
||||
</b:ControlLabel>
|
||||
<b:Controls>
|
||||
<b:TextBox b:id="labelEntry" alternateSize="LARGE"
|
||||
width="97%" enabled="false" ui:field="entryValue"></b:TextBox>
|
||||
</b:Controls>
|
||||
</b:ControlGroup>
|
||||
</g:HTMLPanel>
|
||||
</ui:UiBinder>
|
|
@ -2,7 +2,10 @@ package org.gcube.datacatalogue.grsf_manage_widget.client.view;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.gcube.datacatalogue.grsf_manage_widget.client.GRSFManageWidgetService;
|
||||
import org.gcube.datacatalogue.grsf_manage_widget.client.GRSFManageWidgetServiceAsync;
|
||||
|
@ -88,6 +91,12 @@ public class ManageProductWidget extends Composite{
|
|||
|
||||
@UiField
|
||||
ControlGroup listBoxStatusGroup;
|
||||
|
||||
@UiField
|
||||
ControlGroup annotationAreaGroup;
|
||||
|
||||
@UiField
|
||||
ControlGroup productTypeGroup;
|
||||
|
||||
@UiField
|
||||
Form formUpdate;
|
||||
|
@ -162,6 +171,10 @@ public class ManageProductWidget extends Composite{
|
|||
productShortTitle.setText(bean.getShortTitle());
|
||||
productSource.setText(bean.getSource());
|
||||
|
||||
// check if we need to show more
|
||||
if(bean.getExtrasIfAvailable() != null && !bean.getExtrasIfAvailable().isEmpty())
|
||||
addExtrasAfter(bean, productTypeGroup);
|
||||
|
||||
List<GRSFStatus> statusToShow = new ArrayList<GRSFStatus>(STATUS);
|
||||
statusToShow.remove(bean.getCurrentStatus());
|
||||
listBoxStatus.addItem("Select the new status");
|
||||
|
@ -212,6 +225,29 @@ public class ManageProductWidget extends Composite{
|
|||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add extras if available after controlGroupBefore
|
||||
* @param bean
|
||||
* @param productTypeGroup
|
||||
*/
|
||||
private void addExtrasAfter(ManageProductBean bean,
|
||||
ControlGroup controlGroupBefore) {
|
||||
|
||||
int index = formUpdate.getWidgetIndex(controlGroupBefore);
|
||||
|
||||
Map<String, String> extras = bean.getExtrasIfAvailable();
|
||||
Iterator<Entry<String, String>> iterator = extras.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<java.lang.String, java.lang.String> entry = (Map.Entry<java.lang.String, java.lang.String>) iterator
|
||||
.next();
|
||||
|
||||
formUpdate.insert(new FormEntryModel(entry.getKey(), entry.getValue()), index);
|
||||
index++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@UiHandler("cancelButton")
|
||||
void onCancelButton(ClickEvent ce){
|
||||
|
@ -230,6 +266,14 @@ public class ManageProductWidget extends Composite{
|
|||
listBoxStatusGroup.setType(ControlGroupType.ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
annotationAreaGroup.setType(ControlGroupType.NONE);
|
||||
|
||||
if(annotationArea.getText() == null || annotationArea.getText().isEmpty()){
|
||||
annotationArea.setPlaceholder("An annotation message to send along the update (mandatory)");
|
||||
annotationAreaGroup.setType(ControlGroupType.ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
manageProductModal.setCloseVisible(false);
|
||||
cancelButton.setEnabled(false);
|
||||
|
|
|
@ -5,9 +5,11 @@ import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
|||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
@ -154,10 +156,12 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
|
|||
throw new Exception("Unable to retrieve information for the selected item, sorry");
|
||||
else{
|
||||
|
||||
toReturn = new ManageProductBean();
|
||||
|
||||
// check it is a grsf item, else..
|
||||
List<CkanGroup> groups = product.getGroups();
|
||||
boolean isGrsf = false;
|
||||
|
||||
|
||||
for (CkanGroup ckanGroup : groups) {
|
||||
if(ckanGroup.getName().contains("grsf")){
|
||||
isGrsf = true;
|
||||
|
@ -178,12 +182,24 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
|
|||
String shortTitle = extras.get(SHORT_TITLE_FIELD_KEY);
|
||||
String sources = extras.get(SOURCES_TITLE_FIELD_KEY);
|
||||
String title = product.getTitle();
|
||||
|
||||
// fetch extras
|
||||
GenericResourceReaderExtras entries = new GenericResourceReaderExtras();
|
||||
Set<String> extrasToShow = entries.getLookedUpExtrasKeys();
|
||||
if(extrasToShow != null && !extrasToShow.isEmpty()){
|
||||
Map<String, String> extrasKeyValuePair = new HashMap<String, String>();
|
||||
for (String entryKey : extrasToShow) {
|
||||
String value = extras.get(entryKey);
|
||||
if(value != null && !value.isEmpty())
|
||||
extrasKeyValuePair.put(entryKey, value);
|
||||
}
|
||||
toReturn.setExtrasIfAvailable(extrasKeyValuePair);
|
||||
}
|
||||
|
||||
if(status == null || uuidKB == null || productGRSFType == null)
|
||||
if(status == null || uuidKB == null)
|
||||
throw new Exception("Some information is missing in this record: Status = " + status + ", knowledge_base_uuid = " + uuidKB +
|
||||
", and grsf type is = " + productType);
|
||||
|
||||
toReturn = new ManageProductBean();
|
||||
|
||||
toReturn.setCatalogueIdentifier(productIdentifier);
|
||||
toReturn.setCurrentStatus(GRSFStatus.fromString(status));
|
||||
toReturn.setKnowledgeBaseIdentifier(uuidKB);
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
package org.gcube.datacatalogue.grsf_manage_widget.server.manage;
|
||||
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.client;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.datacatalogue.ckanutillibrary.server.exceptions.ApplicationProfileNotFoundException;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.Query;
|
||||
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
/**
|
||||
* Look up from the IS other information that the widget should lookup
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class GenericResourceReaderExtras {
|
||||
|
||||
private Set<String> lookedUpExtrasKeys = new HashSet<String>();
|
||||
|
||||
private static final String GENERIC_RESOURCE_NAME = "GRSFManageEntries";
|
||||
private static final String GENERIC_RESOURCE_SECONDARY_TYPE = "ApplicationProfile";
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GenericResourceReaderExtras.class);
|
||||
|
||||
// generic resource properties (a list of information)
|
||||
public GenericResourceReaderExtras(){
|
||||
|
||||
String scope = ScopeProvider.instance.get();
|
||||
logger.debug("Trying to fetch applicationProfile profile from the infrastructure for " + GENERIC_RESOURCE_NAME + " scope: " + scope);
|
||||
|
||||
try {
|
||||
Query q = new QueryBox("for $profile in collection('/db/Profiles/GenericResource')//Resource " +
|
||||
"where $profile/Profile/SecondaryType/string() eq '"+ GENERIC_RESOURCE_SECONDARY_TYPE + "' and $profile/Profile/Name/string() " +
|
||||
" eq '" + GENERIC_RESOURCE_NAME + "'" +
|
||||
"return $profile");
|
||||
|
||||
DiscoveryClient<String> client = client();
|
||||
List<String> appProfile = client.submit(q);
|
||||
|
||||
if (appProfile == null || appProfile.size() == 0)
|
||||
throw new ApplicationProfileNotFoundException("Your applicationProfile is not registered in the infrastructure");
|
||||
else {
|
||||
|
||||
String elem = appProfile.get(0);
|
||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Node node = docBuilder.parse(new InputSource(new StringReader(elem))).getDocumentElement();
|
||||
XPathHelper helper = new XPathHelper(node);
|
||||
|
||||
List<String> currValue = null;
|
||||
currValue = helper.evaluate("/Resource/Profile/Body/text()");
|
||||
|
||||
if (currValue != null && currValue.size() > 0) {
|
||||
String body = currValue.get(0);
|
||||
String[] splittedSet = body.split(",");
|
||||
if(splittedSet != null && splittedSet.length > 0)
|
||||
for (String entry : splittedSet) {
|
||||
String trimmed = entry.trim();
|
||||
if(trimmed.isEmpty())
|
||||
continue;
|
||||
lookedUpExtrasKeys.add(trimmed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("Extras entries are " + lookedUpExtrasKeys);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error while trying to fetch applicationProfile profile from the infrastructure", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Set<String> getLookedUpExtrasKeys() {
|
||||
return lookedUpExtrasKeys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GenericResourceReaderExtras [lookedUpExtrasKeys="
|
||||
+ lookedUpExtrasKeys + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package org.gcube.datacatalogue.grsf_manage_widget.shared;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The bean to be managed by some people (e.g., GRSF).
|
||||
|
@ -17,6 +18,7 @@ public class ManageProductBean implements Serializable{
|
|||
private String type; // Fishery or Stock type (e.g., Assessment_Unit, Marine Resource and so on)
|
||||
private String grsfType; // fishery/stock
|
||||
private String source; // the current source
|
||||
private Map<String, String> extrasIfAvailable;
|
||||
|
||||
// info that could change
|
||||
private GRSFStatus currentStatus;
|
||||
|
@ -36,6 +38,7 @@ public class ManageProductBean implements Serializable{
|
|||
* @param type
|
||||
* @param grsfType
|
||||
* @param source
|
||||
* @param extrasIfAvailable
|
||||
* @param currentStatus
|
||||
* @param newStatus
|
||||
* @param annotation
|
||||
|
@ -43,8 +46,8 @@ public class ManageProductBean implements Serializable{
|
|||
public ManageProductBean(String itemTitle, String semanticId,
|
||||
String shortTitle, String catalogueIdentifier,
|
||||
String knowledgeBaseIdentifier, String type, String grsfType,
|
||||
String source, GRSFStatus currentStatus, GRSFStatus newStatus,
|
||||
String annotation) {
|
||||
String source, Map<String, String> extrasIfAvailable,
|
||||
GRSFStatus currentStatus, GRSFStatus newStatus, String annotation) {
|
||||
super();
|
||||
this.itemTitle = itemTitle;
|
||||
this.semanticId = semanticId;
|
||||
|
@ -54,6 +57,7 @@ public class ManageProductBean implements Serializable{
|
|||
this.type = type;
|
||||
this.grsfType = grsfType;
|
||||
this.source = source;
|
||||
this.extrasIfAvailable = extrasIfAvailable;
|
||||
this.currentStatus = currentStatus;
|
||||
this.newStatus = newStatus;
|
||||
this.annotation = annotation;
|
||||
|
@ -146,6 +150,14 @@ public class ManageProductBean implements Serializable{
|
|||
this.shortTitle = shortTitle;
|
||||
}
|
||||
|
||||
public Map<String, String> getExtrasIfAvailable() {
|
||||
return extrasIfAvailable;
|
||||
}
|
||||
|
||||
public void setExtrasIfAvailable(Map<String, String> extrasIfAvailable) {
|
||||
this.extrasIfAvailable = extrasIfAvailable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ManageProductBean [itemTitle=" + itemTitle + ", semanticId="
|
||||
|
@ -153,7 +165,8 @@ public class ManageProductBean implements Serializable{
|
|||
+ ", catalogueIdentifier=" + catalogueIdentifier
|
||||
+ ", knowledgeBaseIdentifier=" + knowledgeBaseIdentifier
|
||||
+ ", type=" + type + ", grsfType=" + grsfType + ", source="
|
||||
+ source + ", currentStatus=" + currentStatus + ", newStatus="
|
||||
+ source + ", extrasIfAvailable=" + extrasIfAvailable
|
||||
+ ", currentStatus=" + currentStatus + ", newStatus="
|
||||
+ newStatus + ", annotation=" + annotation + "]";
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package org.gcube.datacatalogue.grsf_manage_widget.client;
|
||||
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.datacatalogue.grsf_manage_widget.server.manage.GenericResourceReaderExtras;
|
||||
|
||||
public class TestClass {
|
||||
|
||||
//@Test
|
||||
public void test() {
|
||||
ScopeProvider.instance.set("/gcube/devNext/NextNext");
|
||||
GenericResourceReaderExtras entries = new GenericResourceReaderExtras();
|
||||
System.out.println(entries.getLookedUpExtrasKeys());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue