Added and integrated GCatCatalogueConfiguration class

This commit is contained in:
Francesco Mangiacrapa 2022-02-23 16:20:08 +01:00
parent 5e54cfde38
commit 6ea950a627
6 changed files with 162 additions and 57 deletions

View File

@ -10,9 +10,11 @@ import java.util.Map;
import javax.ws.rs.WebApplicationException;
import javax.xml.ws.WebServiceException;
import org.gcube.datacatalogue.utillibrary.shared.Configuration;
import org.gcube.datacatalogue.utillibrary.shared.GCatCatalogueConfiguration;
import org.gcube.gcat.api.configuration.CatalogueConfiguration;
import org.gcube.gcat.api.moderation.CMItemStatus;
import org.gcube.gcat.api.moderation.Moderated;
import org.gcube.gcat.client.Configuration;
import org.gcube.gcat.client.Group;
import org.gcube.gcat.client.Item;
import org.gcube.gcat.client.Resource;
@ -28,7 +30,7 @@ import org.slf4j.LoggerFactory;
public class GCatCaller {
private String catalogueURL;
private Configuration serviceConfiguration;
private GCatCatalogueConfiguration catalogueConfiguration;
private static final Logger LOG = LoggerFactory.getLogger(GCatCaller.class);
@ -309,18 +311,29 @@ public class GCatCaller {
*
* @param reload the reload
* @return the configuration
* @throws MalformedURLException
*/
public Configuration getConfiguration(boolean reload) {
public GCatCatalogueConfiguration getConfiguration(boolean reload) throws MalformedURLException {
LOG.trace("getConfiguration called");
LOG.info("Calling get configuration");
LOG.info("Calling get configuration with reload config: "+reload);
if (reload || serviceConfiguration == null) {
// Must be loa
LOG.warn("\n\n\nI'M USING A MOCK CONFIGURATION\n\n\n\n");
serviceConfiguration = new Configuration();
if (reload || catalogueConfiguration == null) {
catalogueConfiguration = new GCatCatalogueConfiguration();
Configuration gCatConfig = new Configuration();
CatalogueConfiguration gCG = gCatConfig.read();
catalogueConfiguration.setCkanURL(gCG.getCkanURL());
catalogueConfiguration.setContext(gCG.getContext());
catalogueConfiguration.setDefaultOrganization(gCG.getDefaultOrganization());
catalogueConfiguration.setModerationEnabled(gCG.isModerationEnabled());
catalogueConfiguration.setSocialPostEnabled(gCG.isSocialPostEnabled());
catalogueConfiguration.setNotificationToUsersEnabled(gCG.isNotificationToUsersEnabled());
catalogueConfiguration.setSolrURL(gCG.getSolrURL());
catalogueConfiguration.setSupportedOrganizations(gCG.getSupportedOrganizations());
}
return serviceConfiguration;
LOG.info("returning gCatConfig: "+catalogueConfiguration);
return catalogueConfiguration;
}
}

View File

@ -40,7 +40,7 @@ import org.gcube.datacatalogue.utillibrary.server.utils.CatalogueUtilMethods;
import org.gcube.datacatalogue.utillibrary.server.utils.GCubeUtils;
import org.gcube.datacatalogue.utillibrary.server.utils.GcubeContext;
import org.gcube.datacatalogue.utillibrary.server.utils.url.EntityContext;
import org.gcube.datacatalogue.utillibrary.shared.Configuration;
import org.gcube.datacatalogue.utillibrary.shared.GCatCatalogueConfiguration;
import org.gcube.datacatalogue.utillibrary.shared.LandingPages;
import org.gcube.datacatalogue.utillibrary.shared.ResourceBean;
import org.gcube.datacatalogue.utillibrary.shared.RolesCkanGroupOrOrg;
@ -343,7 +343,7 @@ public class DataCatalogueImpl implements DataCatalogue {
*/
public CatalogueContentModeratorSystem getCatalogueContentModerator() {
if (dataCatalogueCMSImpl == null) {
dataCatalogueCMSImpl = new DataCatalogueCMSImpl(CONTEXT, MANAGE_GRSF_PRODUCT_BUTTON, gCatCaller);
dataCatalogueCMSImpl = new DataCatalogueCMSImpl(CONTEXT, gCatCaller);
}
return dataCatalogueCMSImpl;
@ -576,7 +576,7 @@ public class DataCatalogueImpl implements DataCatalogue {
public boolean isModerationEnabled(boolean reloadConfig) {
try {
LOG.info("Called isModerationEnabled with reloadConfig: " + reloadConfig);
Configuration config = gCatCaller.getConfiguration(reloadConfig);
GCatCatalogueConfiguration config = gCatCaller.getConfiguration(reloadConfig);
return config.isModerationEnabled();
} catch (Exception e) {
LOG.error("Error occurred on checking if moderation is enabled. Returning false", e);

View File

@ -20,11 +20,13 @@ import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanDataset;
public interface CatalogueContentModeratorSystem {
/**
* Checks if is content moderator enabled.
* Checks if is moderation enabled.
*
* @return true, if is content moderator enabled
* @param reloadConfig the reload config
* @return true, if is moderation enabled
* @throws MalformedURLException
*/
boolean isContentModeratorEnabled();
boolean isModerationEnabled(boolean reloadConfig) throws MalformedURLException;
/**
* Gets the list items for status.
@ -72,7 +74,7 @@ public interface CatalogueContentModeratorSystem {
/**
* Approve item.
*
* @param itemName the item name
* @param itemName the item name
* @param moderatorMessage the moderator message
* @throws WebApplicationException the web application exception
* @throws MalformedURLException the malformed URL exception

View File

@ -33,34 +33,29 @@ import org.slf4j.LoggerFactory;
public class DataCatalogueCMSImpl implements CatalogueContentModeratorSystem {
private static final Logger LOG = LoggerFactory.getLogger(DataCatalogueCMSImpl.class);
private String runningScope;
private boolean isContentModeratorEnabled;
private GCatCaller gCatCaller;
/**
* Instantiates a new data catalogue CMS impl.
*
* @param runningScope the running scope
* @param isContentModeratorEnabled the is content moderator enabled
* @param gCatCaller the g cat caller
* @param runningScope the running scope
* @param gCatCaller the g cat caller
*/
public DataCatalogueCMSImpl(String runningScope, boolean isContentModeratorEnabled, GCatCaller gCatCaller) {
public DataCatalogueCMSImpl(String runningScope, GCatCaller gCatCaller) {
this.runningScope = runningScope;
this.isContentModeratorEnabled = isContentModeratorEnabled;
this.gCatCaller = gCatCaller;
}
/**
* Checks if is content moderator enabled.
* Checks if is Moderation is enabled in the working scope
*
* @return true, if is content moderator enabled
* @throws MalformedURLException
*/
@Override
public boolean isContentModeratorEnabled() {
return isContentModeratorEnabled;
public boolean isModerationEnabled(boolean reloadConfig) throws MalformedURLException {
return gCatCaller.getConfiguration(reloadConfig).isModerationEnabled();
}
/**
@ -98,7 +93,7 @@ public class DataCatalogueCMSImpl implements CatalogueContentModeratorSystem {
* Permanently delete.
*
* @param datasetName the dataset name
* @throws WebServiceException the web service exception
* @throws WebServiceException the web service exception
* @throws MalformedURLException the malformed URL exception
*/
@Override
@ -165,7 +160,6 @@ public class DataCatalogueCMSImpl implements CatalogueContentModeratorSystem {
return listDataset;
}
/**
* Count list items for status.
*
@ -207,18 +201,17 @@ public class DataCatalogueCMSImpl implements CatalogueContentModeratorSystem {
checkNotNull(theStatus);
// TODO MUST BE CHANGED FOR THE STATUS
org.json.simple.JSONArray jsonArray = null;
/*String datasetNames = null;
if(theStatus.equals(ItemStatus.PUBLISHED)) {
datasetNames = gCatCaller.getListItems(limit, offset);
}else {
CMItemStatus cmiStatus = toCMStatus(theStatus);
datasetNames = gCatCaller.getListItemsForCMStatus(cmiStatus, limit, offset);
}*/
/*
* String datasetNames = null; if(theStatus.equals(ItemStatus.PUBLISHED)) {
* datasetNames = gCatCaller.getListItems(limit, offset); }else { CMItemStatus
* cmiStatus = toCMStatus(theStatus); datasetNames =
* gCatCaller.getListItemsForCMStatus(cmiStatus, limit, offset); }
*/
CMItemStatus cmiStatus = toCMStatus(theStatus);
String datasetNames = gCatCaller.getListItemsForCMStatus(cmiStatus, limit, offset);
if (datasetNames != null) {
LOG.debug("for status " + theStatus + " found dataset: " + datasetNames);
JSONParser parser = new JSONParser();

View File

@ -1,16 +0,0 @@
package org.gcube.datacatalogue.utillibrary.shared;
//THIS IS A MOCK
public class Configuration {
boolean moderationEnabled = true;
public Configuration(){
}
public boolean isModerationEnabled() {
return moderationEnabled;
}
}

View File

@ -0,0 +1,113 @@
package org.gcube.datacatalogue.utillibrary.shared;
import java.io.Serializable;
import java.util.Set;
public class GCatCatalogueConfiguration implements Serializable {
/**
*
*/
private static final long serialVersionUID = -1250433017161647236L;
private String context;
private String defaultOrganization;
private Set<String> supportedOrganizations;
private String ckanURL;
private String solrURL;
private boolean socialPostEnabled;
private boolean notificationToUsersEnabled;
private boolean moderationEnabled;
public GCatCatalogueConfiguration() {
}
public String getContext() {
return context;
}
public String getDefaultOrganization() {
return defaultOrganization;
}
public Set<String> getSupportedOrganizations() {
return supportedOrganizations;
}
public String getCkanURL() {
return ckanURL;
}
public String getSolrURL() {
return solrURL;
}
public boolean isSocialPostEnabled() {
return socialPostEnabled;
}
public boolean isNotificationToUsersEnabled() {
return notificationToUsersEnabled;
}
public boolean isModerationEnabled() {
return moderationEnabled;
}
public void setContext(String context) {
this.context = context;
}
public void setDefaultOrganization(String defaultOrganization) {
this.defaultOrganization = defaultOrganization;
}
public void setSupportedOrganizations(Set<String> supportedOrganizations) {
this.supportedOrganizations = supportedOrganizations;
}
public void setCkanURL(String ckanURL) {
this.ckanURL = ckanURL;
}
public void setSolrURL(String solrURL) {
this.solrURL = solrURL;
}
public void setSocialPostEnabled(boolean socialPostEnabled) {
this.socialPostEnabled = socialPostEnabled;
}
public void setNotificationToUsersEnabled(boolean notificationToUsersEnabled) {
this.notificationToUsersEnabled = notificationToUsersEnabled;
}
public void setModerationEnabled(boolean moderationEnabled) {
this.moderationEnabled = moderationEnabled;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("GCatCatalogueConfiguration [context=");
builder.append(context);
builder.append(", defaultOrganization=");
builder.append(defaultOrganization);
builder.append(", supportedOrganizations=");
builder.append(supportedOrganizations);
builder.append(", ckanURL=");
builder.append(ckanURL);
builder.append(", solrURL=");
builder.append(solrURL);
builder.append(", socialPostEnabled=");
builder.append(socialPostEnabled);
builder.append(", notificationToUsersEnabled=");
builder.append(notificationToUsersEnabled);
builder.append(", moderationEnabled=");
builder.append(moderationEnabled);
builder.append("]");
return builder.toString();
}
}