Fixing configuration management
This commit is contained in:
parent
0a31aeb229
commit
1fb509ef48
|
@ -91,7 +91,10 @@ public abstract class Record extends CKANPackage {
|
|||
|
||||
protected Set<FileContainer> wsUploadedFiles;
|
||||
|
||||
protected GRSFCatalogueConfiguration configuration;
|
||||
|
||||
public Record() {
|
||||
super(GRSFCatalogueConfigurationFactory.getInstance());
|
||||
this.objectMapper = new ObjectMapper();
|
||||
this.patch = false;
|
||||
}
|
||||
|
@ -251,8 +254,7 @@ public abstract class Record extends CKANPackage {
|
|||
String recordURL = uriResolver.getCatalogueItemURL(grsfUUID);
|
||||
map.put(RECORD_URL_TEMPLATE_PROPERTY_KEY, recordURL);
|
||||
|
||||
GRSFCatalogueConfiguration grsfCC = GRSFCatalogueConfigurationFactory.getInstance();
|
||||
map.put(INCLUDE_SENSITIVE_TEMPLATE_PROPERTY_KEY, grsfCC.isIncludeSensitive());
|
||||
map.put(INCLUDE_SENSITIVE_TEMPLATE_PROPERTY_KEY, configuration.isIncludeSensitive());
|
||||
|
||||
map.put(IS_PATCH_TEMPLATE_PROPERTY_KEY, patch);
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ package org.gcube.grsf.publisher.configuration;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.gcat.configuration.service.ServiceCatalogueConfiguration;
|
||||
import org.gcube.grsf.publisher.utils.OrganizationUtils;
|
||||
|
||||
|
@ -12,52 +12,32 @@ import org.gcube.grsf.publisher.utils.OrganizationUtils;
|
|||
*/
|
||||
public class GRSFCatalogueConfiguration extends ServiceCatalogueConfiguration {
|
||||
|
||||
protected Set<String> grsfSupportedOrganizations;
|
||||
protected boolean includeSensitive;
|
||||
|
||||
public GRSFCatalogueConfiguration() {
|
||||
Map<String,String> organizationMap = OrganizationUtils.getInstance().getOrganizations();
|
||||
this.grsfSupportedOrganizations = organizationMap.keySet();
|
||||
this.supportedOrganizations = organizationMap.keySet();
|
||||
this.defaultOrganization = "grsf";
|
||||
this.includeSensitive = true;
|
||||
this.socialPostEnabled = false;
|
||||
this.notificationToUsersEnabled = false;
|
||||
}
|
||||
|
||||
@JsonGetter(value = SOCIAL_POST_ENABLED_KEY)
|
||||
public boolean isSocialPostEnabledOriginal() {
|
||||
return socialPostEnabled;
|
||||
}
|
||||
|
||||
@JsonGetter(value = NOTIFICATION_TO_USER_ENABLED_KEY)
|
||||
public boolean isNotificationToUsersEnabledOriginal() {
|
||||
return notificationToUsersEnabled;
|
||||
}
|
||||
|
||||
@JsonGetter(value = MODERATION_ENABLED_KEY)
|
||||
public boolean isModerationEnabledOriginal() {
|
||||
return moderationEnabled;
|
||||
}
|
||||
|
||||
public boolean isSocialPostEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isNotificationToUsersEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModerationEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@JsonGetter(value = SUPPORTED_ORGANIZATIONS_KEY)
|
||||
public Set<String> getOriginalSupportedOrganizations() {
|
||||
return supportedOrganizations;
|
||||
@Override
|
||||
public void setDefaultOrganization(String defaultOrganization) {
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedOrganizations() {
|
||||
return grsfSupportedOrganizations;
|
||||
public void setSupportedOrganizations(Set<String> supportedOrganizations) {
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
|
||||
public boolean isIncludeSensitive() {
|
||||
return includeSensitive;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ import org.gcube.gcat.persistence.ckan.CKANUser;
|
|||
import org.gcube.gcat.persistence.ckan.cache.CKANUserCache;
|
||||
import org.gcube.grsf.publisher.annotation.PATCH;
|
||||
import org.gcube.grsf.publisher.annotation.PURGE;
|
||||
import org.gcube.grsf.publisher.configuration.GRSFCatalogueConfiguration;
|
||||
import org.gcube.grsf.publisher.configuration.GRSFCatalogueConfigurationFactory;
|
||||
import org.gcube.grsf.publisher.rest.BaseREST;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -222,7 +224,7 @@ public class Configuration extends BaseREST implements org.gcube.gcat.api.interf
|
|||
// @AuthorizationControl(allowedRoles={Role.CATALOGUE_MANAGER}, exception=NotAuthorizedException.class)
|
||||
public Response create(String json) throws WebServiceException {
|
||||
try {
|
||||
ServiceCatalogueConfiguration catalogueConfiguration = ServiceCatalogueConfiguration.getServiceCatalogueConfiguration(json);
|
||||
ServiceCatalogueConfiguration catalogueConfiguration = ServiceCatalogueConfiguration.getServiceCatalogueConfiguration(json, GRSFCatalogueConfiguration.class);
|
||||
checkContext(CURRENT_CONTEXT_PATH_PARAMETER, catalogueConfiguration);
|
||||
String ret = createOrUpdate(catalogueConfiguration);
|
||||
ResponseBuilder responseBuilder = Response.status(Status.CREATED);
|
||||
|
@ -301,9 +303,9 @@ public class Configuration extends BaseREST implements org.gcube.gcat.api.interf
|
|||
@Override
|
||||
public Response read() throws WebServiceException {
|
||||
try {
|
||||
ServiceCatalogueConfiguration catalogueConfiguration = CatalogueConfigurationFactory.getInstance();
|
||||
String configuration = catalogueConfiguration.toJsonString();
|
||||
logger.debug("Configuration in context {} is {}", catalogueConfiguration.getContext(), configuration);
|
||||
GRSFCatalogueConfiguration grsfCC = GRSFCatalogueConfigurationFactory.getInstance();
|
||||
String configuration = grsfCC.toJsonString();
|
||||
logger.debug("Configuration in context {} is {}", grsfCC.getContext(), configuration);
|
||||
ResponseBuilder responseBuilder = Response.status(Status.OK);
|
||||
if(configuration!=null) {
|
||||
responseBuilder.entity(configuration).type(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8);
|
||||
|
@ -352,9 +354,9 @@ public class Configuration extends BaseREST implements org.gcube.gcat.api.interf
|
|||
@OperationId("Create or Update")
|
||||
public String createOrUpdate(@PathParam(CONTEXT_FULLNAME_PARAMETER) String context, String json) throws WebServiceException {
|
||||
try {
|
||||
ServiceCatalogueConfiguration catalogueConfiguration = ServiceCatalogueConfiguration.getServiceCatalogueConfiguration(json);
|
||||
checkContext(context, catalogueConfiguration);
|
||||
return createOrUpdate(catalogueConfiguration);
|
||||
GRSFCatalogueConfiguration grsfCatalogueConfiguration = ServiceCatalogueConfiguration.getServiceCatalogueConfiguration(json, GRSFCatalogueConfiguration.class);
|
||||
checkContext(context, grsfCatalogueConfiguration);
|
||||
return createOrUpdate(grsfCatalogueConfiguration);
|
||||
}catch (WebApplicationException e) {
|
||||
throw e;
|
||||
}catch (Exception e) {
|
||||
|
@ -365,11 +367,11 @@ public class Configuration extends BaseREST implements org.gcube.gcat.api.interf
|
|||
@Override
|
||||
public Response update(String json) throws WebServiceException {
|
||||
try {
|
||||
ServiceCatalogueConfiguration catalogueConfiguration = ServiceCatalogueConfiguration.getServiceCatalogueConfiguration(json);
|
||||
GRSFCatalogueConfiguration grsfCatalogueConfiguration = ServiceCatalogueConfiguration.getServiceCatalogueConfiguration(json, GRSFCatalogueConfiguration.class);
|
||||
checkContext(CURRENT_CONTEXT_PATH_PARAMETER);
|
||||
catalogueConfiguration = CatalogueConfigurationFactory.createOrUpdate(catalogueConfiguration);
|
||||
String configuration = catalogueConfiguration.toJsonString();
|
||||
logger.debug("Configuration in context {} has been updated to {}", catalogueConfiguration.getContext(), configuration);
|
||||
grsfCatalogueConfiguration = GRSFCatalogueConfigurationFactory.createOrUpdate(grsfCatalogueConfiguration);
|
||||
String configuration = grsfCatalogueConfiguration.toJsonString();
|
||||
logger.debug("Configuration in context {} has been updated to {}", grsfCatalogueConfiguration.getContext(), configuration);
|
||||
ResponseBuilder responseBuilder = Response.status(Status.OK);
|
||||
if(configuration!=null) {
|
||||
responseBuilder.entity(configuration).type(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8);
|
||||
|
@ -451,7 +453,7 @@ public class Configuration extends BaseREST implements org.gcube.gcat.api.interf
|
|||
configuration.set(fieldName, node.get(fieldName));
|
||||
}
|
||||
|
||||
ServiceCatalogueConfiguration newCatalogueConfiguration = ServiceCatalogueConfiguration.getServiceCatalogueConfiguration(configuration);
|
||||
ServiceCatalogueConfiguration newCatalogueConfiguration = ServiceCatalogueConfiguration.getServiceCatalogueConfiguration(configuration, GRSFCatalogueConfiguration.class);
|
||||
newCatalogueConfiguration = CatalogueConfigurationFactory.createOrUpdate(newCatalogueConfiguration);
|
||||
String ret = newCatalogueConfiguration.toJsonString();
|
||||
logger.debug("Configuration in context {} has been patched to {}", catalogueConfiguration.getContext(), ret);
|
||||
|
|
|
@ -64,8 +64,8 @@ public class ContextTest {
|
|||
|
||||
ROOT_PROD = "/d4science.research-infrastructures.eu";
|
||||
|
||||
DEFAULT_TEST_SCOPE = DEVVRE;
|
||||
// DEFAULT_TEST_SCOPE = VRE_GRSF_PRE;
|
||||
// DEFAULT_TEST_SCOPE = DEVVRE;
|
||||
DEFAULT_TEST_SCOPE = VRE_GRSF_PRE;
|
||||
|
||||
properties = new Properties();
|
||||
InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(CONFIG_INI_FILENAME);
|
||||
|
|
|
@ -5,12 +5,16 @@ import org.gcube.grsf.publisher.ContextTest;
|
|||
import org.gcube.grsf.publisher.configuration.isproxies.impl.GRSFFacetBasedISConfigurationProxy;
|
||||
import org.gcube.grsf.publisher.configuration.isproxies.impl.GRSFFacetBasedISConfigurationProxyFactory;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class ConfigurationTest extends ContextTest {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ConfigurationTest.class);
|
||||
|
||||
@Test
|
||||
public void testFacetBasedConf() throws Exception {
|
||||
String context = SecretManagerProvider.instance.get().getContext();
|
||||
|
@ -19,4 +23,11 @@ public class ConfigurationTest extends ContextTest {
|
|||
facetBasedISConfigurationProxy.installQueryTemplate();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfiguration() throws Exception {
|
||||
GRSFCatalogueConfiguration grsfCC = GRSFCatalogueConfigurationFactory.getInstance();
|
||||
String configuration = grsfCC.toJsonString();
|
||||
logger.info("Configuration in context {} is {}", grsfCC.getContext(), configuration);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue