moved isAdmin check in the widget. Changed Product/Record term with Item for consistency with the portlet/widgets of the catalogue
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/grsf-manage-widget@142657 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
9205b235fc
commit
4714974231
10
.project
10
.project
|
@ -25,11 +25,6 @@
|
|||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.google.gdt.eclipse.core.webAppProjectValidator</name>
|
||||
<arguments>
|
||||
|
@ -40,6 +35,11 @@
|
|||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -12,7 +12,7 @@
|
|||
|
||||
<groupId>org.gcube.portlets.widgets</groupId>
|
||||
<artifactId>grsf-manage-widget</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
<name>gCube GRSF Manage widget</name>
|
||||
|
||||
<scm>
|
||||
|
|
|
@ -21,4 +21,9 @@ public interface GRSFManageWidgetService extends RemoteService {
|
|||
* @throws Exception
|
||||
*/
|
||||
ManageProductBean getProductBeanById(String identifier) throws Exception;
|
||||
|
||||
/**
|
||||
* check if the user has the role to manage the item
|
||||
*/
|
||||
boolean isAdminUser();
|
||||
}
|
||||
|
|
|
@ -16,4 +16,6 @@ public interface GRSFManageWidgetServiceAsync {
|
|||
void getProductBeanById(String identifier,
|
||||
AsyncCallback<ManageProductBean> callback);
|
||||
|
||||
void isAdminUser(AsyncCallback<Boolean> callback);
|
||||
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ public class ManageProductWidget extends Composite{
|
|||
AlertBlock infoBlock;
|
||||
|
||||
@UiField
|
||||
TextBox nameTextBox;
|
||||
TextArea nameTextArea;
|
||||
|
||||
@UiField
|
||||
TextBox currentStatus;
|
||||
|
@ -85,75 +85,111 @@ public class ManageProductWidget extends Composite{
|
|||
|
||||
public static final String LOADING_IMAGE_URL = GWT.getModuleBaseURL() + "../images/loader.gif";
|
||||
private final static List<GRSFStatus> STATUS = new ArrayList<GRSFStatus>(Arrays.asList(GRSFStatus.values()));
|
||||
private final static String STATUS_UPDATE_SUCCESS = "The product was correctly updated. Thanks for your collaboration!";
|
||||
private final static String STATUS_UPDATE_ERROR = "Sorry, there was a problem while trying to update the status of this product";
|
||||
private final static String STATUS_UPDATE_SUCCESS = "The item has been correctly updated. Thanks for your collaboration!";
|
||||
private final static String STATUS_UPDATE_ERROR = "Sorry, there was a problem while trying to update the status of this item";
|
||||
protected static final String ERROR_ON_RETRIEVING_BEAN = "It seems there was a problem while contacting the service...";
|
||||
protected static final String NO_GRSF_RECORD_BEAN = "This record is not a GRSF record, thus it cannot be managed";
|
||||
protected static final String NO_GRSF_RECORD_BEAN = "This item is not a GRSF record, thus it cannot be managed";
|
||||
|
||||
protected static final String ERROR_ON_ROLE_CHECK = "Sorry but the service was not able to check if you have the rights to manage an item."
|
||||
+ " You are suggested to contact the VRE Manager.";
|
||||
private ManageProductBean bean;
|
||||
|
||||
public ManageProductWidget(String productIdentifier) {
|
||||
initWidget(uiBinder.createAndBindUi(this));
|
||||
|
||||
if(productIdentifier == null || productIdentifier.isEmpty()){
|
||||
GWT.log("The received product identifier is null..");
|
||||
GWT.log("The received item identifier is null..");
|
||||
return;
|
||||
}
|
||||
|
||||
GWT.log("Product identifier is " + productIdentifier);
|
||||
GWT.log("item identifier is " + productIdentifier);
|
||||
|
||||
// start loader service
|
||||
loadingImage.setUrl(LOADING_IMAGE_URL);
|
||||
loadingImage.setVisible(true);
|
||||
|
||||
manageProductModal.show();
|
||||
|
||||
// async request to fetch the product
|
||||
retrieveProductBean(productIdentifier);
|
||||
manageProductModal.show();
|
||||
}
|
||||
|
||||
private void retrieveProductBean(String productIdentifier) {
|
||||
private void retrieveProductBean(final String productIdentifier) {
|
||||
|
||||
service.getProductBeanById(productIdentifier, new AsyncCallback<ManageProductBean>() {
|
||||
// check if it is an administrator
|
||||
service.isAdminUser(new AsyncCallback<Boolean>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(ManageProductBean result) {
|
||||
public void onSuccess(Boolean result) {
|
||||
|
||||
if(result != null){
|
||||
bean = result;
|
||||
annotationArea.setText("");
|
||||
infoBlock.setVisible(false);
|
||||
nameTextBox.setText(bean.getProductName());
|
||||
currentStatus.setText(bean.getCurrentStatus().toString());
|
||||
productType.setText(bean.getProductType());
|
||||
List<GRSFStatus> statusToShow = new ArrayList<GRSFStatus>(STATUS);
|
||||
statusToShow.remove(bean.getCurrentStatus());
|
||||
listBoxStatus.addItem("Select the new status");
|
||||
listBoxStatus.getElement().<SelectElement>cast().getOptions().getItem(0).setDisabled(true);
|
||||
for (GRSFStatus availableStatus : statusToShow) {
|
||||
listBoxStatus.addItem(availableStatus.toString());
|
||||
}
|
||||
listBoxStatus.setSelectedIndex(0);
|
||||
}
|
||||
else{
|
||||
showInfo(ERROR_ON_RETRIEVING_BEAN, AlertType.ERROR);
|
||||
if(!result){
|
||||
|
||||
showInfo(ERROR_ON_ROLE_CHECK, AlertType.ERROR);
|
||||
|
||||
// hide the form and disable the send button
|
||||
formUpdate.setVisible(false);
|
||||
confirmButton.setEnabled(false);
|
||||
loadingImage.setVisible(false);
|
||||
|
||||
}else{
|
||||
service.getProductBeanById(productIdentifier, new AsyncCallback<ManageProductBean>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(ManageProductBean result) {
|
||||
|
||||
if(result != null){
|
||||
bean = result;
|
||||
annotationArea.setText("");
|
||||
infoBlock.setVisible(false);
|
||||
nameTextArea.setText(bean.getProductName());
|
||||
currentStatus.setText(bean.getCurrentStatus().toString());
|
||||
productType.setText(bean.getProductType());
|
||||
List<GRSFStatus> statusToShow = new ArrayList<GRSFStatus>(STATUS);
|
||||
statusToShow.remove(bean.getCurrentStatus());
|
||||
listBoxStatus.addItem("Select the new status");
|
||||
listBoxStatus.getElement().<SelectElement>cast().getOptions().getItem(0).setDisabled(true);
|
||||
for (GRSFStatus availableStatus : statusToShow) {
|
||||
listBoxStatus.addItem(availableStatus.toString());
|
||||
}
|
||||
listBoxStatus.setSelectedIndex(0);
|
||||
}
|
||||
else{
|
||||
showInfo(ERROR_ON_RETRIEVING_BEAN, AlertType.ERROR);
|
||||
formUpdate.setVisible(false);
|
||||
confirmButton.setEnabled(false);
|
||||
}
|
||||
|
||||
loadingImage.setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
|
||||
if(caught instanceof NoGRSFRecordException)
|
||||
showInfo(NO_GRSF_RECORD_BEAN, AlertType.WARNING);
|
||||
else
|
||||
showInfo(caught.getMessage(), AlertType.ERROR);
|
||||
|
||||
// hide the form and disable the send button
|
||||
formUpdate.setVisible(false);
|
||||
confirmButton.setEnabled(false);
|
||||
loadingImage.setVisible(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
loadingImage.setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
|
||||
if(caught instanceof NoGRSFRecordException)
|
||||
showInfo(NO_GRSF_RECORD_BEAN, AlertType.WARNING);
|
||||
else
|
||||
showInfo(caught.getMessage(), AlertType.ERROR);
|
||||
|
||||
showInfo(ERROR_ON_ROLE_CHECK, AlertType.ERROR);
|
||||
|
||||
// hide the form and disable the send button
|
||||
formUpdate.setVisible(false);
|
||||
confirmButton.setEnabled(false);
|
||||
loadingImage.setVisible(false);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
}
|
||||
</ui:style>
|
||||
<g:HTMLPanel>
|
||||
<b:Modal ui:field="manageProductModal" title="Manage product"
|
||||
<b:Modal ui:field="manageProductModal" title="Manage item"
|
||||
backdrop="STATIC" keyboard="true" animation="true" closeVisible="true">
|
||||
<g:VerticalPanel width="100%">
|
||||
|
||||
|
@ -23,23 +23,23 @@
|
|||
<b:Form type="VERTICAL" visible="true" ui:field="formUpdate" width="100%">
|
||||
|
||||
<b:ControlGroup ui:field="productTitleGroup">
|
||||
<b:ControlLabel for="name" title="Product name">
|
||||
<b>Product Name:</b>
|
||||
<b:ControlLabel for="name" title="Item name">
|
||||
<b>Item Name:</b>
|
||||
</b:ControlLabel>
|
||||
<b:Controls>
|
||||
<b:TextBox alternateSize="LARGE" placeholder="Product name"
|
||||
enabled="false" width="97%" b:id="name" title="Product name"
|
||||
ui:field="nameTextBox" />
|
||||
<b:TextArea alternateSize="LARGE" placeholder="Item name"
|
||||
enabled="false" width="97%" b:id="name" title="Item name"
|
||||
ui:field="nameTextArea" />
|
||||
</b:Controls>
|
||||
</b:ControlGroup>
|
||||
|
||||
<b:ControlGroup ui:field="currentStatusGroup">
|
||||
<b:ControlLabel for="currentStatus"
|
||||
title="The current status of this product">
|
||||
<b>Product Current Status:</b></b:ControlLabel>
|
||||
title="The current status of this Item">
|
||||
<b>Item Current Status:</b></b:ControlLabel>
|
||||
<b:Controls>
|
||||
<b:TextBox b:id="currentStatus" alternateSize="LARGE"
|
||||
enabled="false" width="97%" title="The current status of this product"
|
||||
enabled="false" width="97%" title="The current status of this Item"
|
||||
ui:field="currentStatus">
|
||||
</b:TextBox>
|
||||
</b:Controls>
|
||||
|
@ -47,8 +47,8 @@
|
|||
|
||||
<b:ControlGroup ui:field="listBoxStatusGroup">
|
||||
<b:ControlLabel for="listboxStatus"
|
||||
title="The new status of this product">
|
||||
<b>Product New Status:</b></b:ControlLabel>
|
||||
title="The new status of this Item">
|
||||
<b>Item New Status:</b></b:ControlLabel>
|
||||
<b:Controls>
|
||||
<b:ListBox b:id="listboxStatus" alternateSize="LARGE"
|
||||
width="97%" title="Select a new status" enabled="true"
|
||||
|
@ -58,11 +58,11 @@
|
|||
|
||||
<b:ControlGroup ui:field="productTypeGroup">
|
||||
<b:ControlLabel for="productType"
|
||||
title="The product type">
|
||||
<b>Product Type:</b></b:ControlLabel>
|
||||
title="The Item type">
|
||||
<b>Item Type:</b></b:ControlLabel>
|
||||
<b:Controls>
|
||||
<b:TextBox b:id="productType" alternateSize="LARGE"
|
||||
width="97%" title="The product type" enabled="false" ui:field="productType"></b:TextBox>
|
||||
width="97%" title="The Item type" enabled="false" ui:field="productType"></b:TextBox>
|
||||
</b:Controls>
|
||||
</b:ControlGroup>
|
||||
|
||||
|
|
|
@ -26,7 +26,9 @@ import org.gcube.datacatalogue.grsf_manage_widget.shared.ManageProductBean;
|
|||
import org.gcube.datacatalogue.grsf_manage_widget.shared.ex.NoGRSFRecordException;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
@ -54,7 +56,6 @@ import eu.trentorise.opendata.jackan.model.CkanTag;
|
|||
public class GRSFNotificationService extends RemoteServiceServlet implements GRSFManageWidgetService{
|
||||
|
||||
private static final long serialVersionUID = -4534905087994875893L;
|
||||
//private static Logger logger = LoggerFactory.getLogger(GRSFNotificationService.class);
|
||||
private static final Log logger = LogFactoryUtil.getLog(GRSFNotificationService.class);
|
||||
private static final String SERVICE_POST_METHOD = "/service/updater/post";
|
||||
private static final String ANNOTATION_KEY = "Annotation on update";
|
||||
|
@ -62,6 +63,7 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
|
|||
private static final String STATUS_CUSTOM_FIELD_KEY = "Status";
|
||||
private static final int MAX_TRIAL = 5;
|
||||
public static final String GRSF_UPDATER_SERVICE = "GRSFUpdaterEndPoint";
|
||||
private static final String GRSF_ADMIN_ROLE = "GRSF-Admin";
|
||||
// request post fields
|
||||
private static final String CATALOGUE_ID = "catalog_id";
|
||||
private static final String KB_ID = "record_id";
|
||||
|
@ -80,6 +82,9 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
|
|||
// request url
|
||||
public static final String GCUBE_REQUEST_URL = "gcube-request-url";
|
||||
|
||||
// session info for user
|
||||
public static final String GRSF_ADMIN_SESSION_KEY = "IS_GRSF_ADMIN";
|
||||
|
||||
/**
|
||||
* Instanciate the ckan util library.
|
||||
* Since it needs the scope, we need to check if it is null or not
|
||||
|
@ -145,7 +150,7 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
|
|||
|
||||
// it cannot be enabled in this case ...
|
||||
if(recordType == null || recordType.equals("Source"))
|
||||
throw new NoGRSFRecordException("This is not a GRSF record");
|
||||
throw new NoGRSFRecordException("This is not a GRSF Item");
|
||||
|
||||
if(status == null || uuidKB == null || productType == null)
|
||||
throw new Exception("Some information is missing in this record: Status = " + status + ", knowledge_base_uuid = " + uuidKB +
|
||||
|
@ -158,7 +163,7 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
|
|||
toReturn.setProductName(title);
|
||||
toReturn.setProductType(productType);
|
||||
|
||||
logger.info("Returning product bean " + toReturn);
|
||||
logger.info("Returning item bean " + toReturn);
|
||||
|
||||
|
||||
return toReturn;
|
||||
|
@ -225,7 +230,7 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
|
|||
throw new IllegalArgumentException("GRSF Updater service url cannot be null");
|
||||
|
||||
if(bean == null)
|
||||
throw new IllegalArgumentException("Product bean to manage cannot be null");
|
||||
throw new IllegalArgumentException("Item bean to manage cannot be null");
|
||||
|
||||
try(CloseableHttpClient httpClient = HttpClientBuilder.create().build();){
|
||||
|
||||
|
@ -263,7 +268,7 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
|
|||
return patchProduct(catalogue, bean, username);
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("Unable to update this record" + e.getMessage());
|
||||
logger.error("Unable to update this Item " + e.getMessage());
|
||||
return e.getMessage();
|
||||
}
|
||||
|
||||
|
@ -459,4 +464,34 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
|
|||
logger.debug("Returning user " + user);
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAdminUser() {
|
||||
try{
|
||||
|
||||
Boolean inSession = (Boolean)getThreadLocalRequest().getSession().getAttribute(GRSF_ADMIN_SESSION_KEY);
|
||||
|
||||
if(inSession != null)
|
||||
return inSession;
|
||||
else{
|
||||
PortalContext pContext = PortalContext.getConfiguration();
|
||||
List<GCubeRole> userRoles = new LiferayRoleManager().listRolesByUserAndGroup(
|
||||
pContext.getCurrentUser(getThreadLocalRequest()).getUserId(),
|
||||
pContext.getCurrentGroupId(getThreadLocalRequest()));
|
||||
boolean toSetInSession = false;
|
||||
for (GCubeRole gCubeRole : userRoles) {
|
||||
if(gCubeRole.getRoleName().equals(GRSF_ADMIN_ROLE)){
|
||||
toSetInSession = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
getThreadLocalRequest().getSession().setAttribute(GRSF_ADMIN_SESSION_KEY, toSetInSession);
|
||||
return toSetInSession;
|
||||
}
|
||||
}catch(Exception e){
|
||||
logger.error("Failed to check if the user has role " + GRSF_ADMIN_ROLE, e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue