List of licenses, list of user's organizations and list of profiles is now saved into asl session to speed up the retrieval
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@129489 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
ce63c31343
commit
5ab2406ab2
|
@ -54,6 +54,9 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
public static final String TEST_SCOPE = "/gcube/devsec/devVRE";
|
||||
|
||||
public static final String CKAN_TOKEN_KEY = "ckanToken";
|
||||
public static final String CKAN_LICENSES_KEY = "ckanLicenses";
|
||||
private static final String CKAN_ORGANIZATIONS_KEY = "ckanOrganizations";
|
||||
private static final String CKAN_PROFILES_KEY = "ckanProfiles";
|
||||
|
||||
private Object LOCK = new Object();
|
||||
|
||||
|
@ -145,31 +148,41 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
|
||||
logger.debug("Request for user " + username + " organizations list");
|
||||
List<String> orgsName = new ArrayList<String>();
|
||||
ASLSession session = getASLSession();
|
||||
|
||||
if(getCkanUtilsObj().isSysAdmin(username, getUserCKanTokenFromSession())){
|
||||
|
||||
logger.debug("The user " + username + " is a sysadmin. He can publish everywhere");
|
||||
orgsName = getCkanUtilsObj().getOrganizationsNames(); // get all organizations' names
|
||||
|
||||
}else{
|
||||
|
||||
// We need to retrieve orgs in which the user has the roles ADMIN or EDITOR
|
||||
List<RolesIntoOrganization> rolesToMatch = new ArrayList<RolesIntoOrganization>();
|
||||
rolesToMatch.add(RolesIntoOrganization.EDITOR);
|
||||
rolesToMatch.add(RolesIntoOrganization.ADMIN);
|
||||
|
||||
Map<String, List<RolesIntoOrganization>> orgsAndRoles = getCkanUtilsObj().getGroupsAndRolesByUser(username, rolesToMatch);
|
||||
logger.debug("Result is " + orgsAndRoles);
|
||||
Iterator<Entry<String, List<RolesIntoOrganization>>> iterator = orgsAndRoles.entrySet().iterator();
|
||||
|
||||
// get the names
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, java.util.List<RolesIntoOrganization>> entry = (Map.Entry<String, java.util.List<RolesIntoOrganization>>) iterator
|
||||
.next();
|
||||
orgsName.add(entry.getKey());
|
||||
logger.debug("The user has a role ADMIN/EDITOR into org " + entry.getKey());
|
||||
}
|
||||
if(session.getAttribute(CKAN_ORGANIZATIONS_KEY) != null){
|
||||
orgsName = (List<String>)session.getAttribute(CKAN_ORGANIZATIONS_KEY);
|
||||
logger.debug("List of organizations was into session");
|
||||
}
|
||||
else{
|
||||
if(getCkanUtilsObj().isSysAdmin(username, getUserCKanTokenFromSession())){
|
||||
|
||||
logger.debug("The user " + username + " is a sysadmin. He can publish everywhere");
|
||||
orgsName = getCkanUtilsObj().getOrganizationsNames(); // get all organizations' names
|
||||
|
||||
}else{
|
||||
|
||||
// We need to retrieve orgs in which the user has the roles ADMIN or EDITOR
|
||||
List<RolesIntoOrganization> rolesToMatch = new ArrayList<RolesIntoOrganization>();
|
||||
rolesToMatch.add(RolesIntoOrganization.EDITOR);
|
||||
rolesToMatch.add(RolesIntoOrganization.ADMIN);
|
||||
|
||||
Map<String, List<RolesIntoOrganization>> orgsAndRoles = getCkanUtilsObj().getGroupsAndRolesByUser(username, rolesToMatch);
|
||||
logger.debug("Result is " + orgsAndRoles);
|
||||
Iterator<Entry<String, List<RolesIntoOrganization>>> iterator = orgsAndRoles.entrySet().iterator();
|
||||
|
||||
// get the names
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, java.util.List<RolesIntoOrganization>> entry = (Map.Entry<String, java.util.List<RolesIntoOrganization>>) iterator
|
||||
.next();
|
||||
orgsName.add(entry.getKey());
|
||||
logger.debug("The user has a role ADMIN/EDITOR into org " + entry.getKey());
|
||||
}
|
||||
}
|
||||
session.setAttribute(CKAN_ORGANIZATIONS_KEY, orgsName);
|
||||
logger.debug("Organizations name for user " + username + " has been saved into session");
|
||||
}
|
||||
|
||||
return orgsName;
|
||||
}
|
||||
|
||||
|
@ -193,7 +206,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
* @param chosenLicense
|
||||
* @return
|
||||
*/
|
||||
private String findLicenseIdByLicense(String chosenLicense) {
|
||||
private String findLicenseIdByLicense(String chosenLicense) {
|
||||
return getCkanUtilsObj().findLicenseIdByLicense(chosenLicense);
|
||||
}
|
||||
|
||||
|
@ -205,69 +218,91 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
|
||||
List<MetaDataProfileBean> beans = new ArrayList<MetaDataProfileBean>();
|
||||
|
||||
try {
|
||||
ASLSession session = getASLSession();
|
||||
String username = session.getUsername();
|
||||
logger.debug("User in session is " + username);
|
||||
|
||||
DataCalogueMetadataFormatReader reader = new DataCalogueMetadataFormatReader();
|
||||
if(session.getAttribute(CKAN_PROFILES_KEY) != null){
|
||||
beans = (List<MetaDataProfileBean>)session.getAttribute(CKAN_PROFILES_KEY);
|
||||
logger.debug("List of profiles was into session");
|
||||
}
|
||||
else{
|
||||
|
||||
for (MetadataType mt : reader.getListOfMetadataTypes()) {
|
||||
MetadataFormat metadata = reader.getMetadataFormatForMetadataType(mt);
|
||||
try {
|
||||
|
||||
// we need to wrap the list of metadata
|
||||
List<MetadataFieldWrapper> wrapperList = new ArrayList<MetadataFieldWrapper>();
|
||||
List<MetadataField> toWrap = metadata.getMetadataFields();
|
||||
for(MetadataField metadataField: toWrap){
|
||||
DataCalogueMetadataFormatReader reader = new DataCalogueMetadataFormatReader();
|
||||
|
||||
MetadataFieldWrapper wrapperObj = new MetadataFieldWrapper();
|
||||
wrapperObj.setDefaulValue(metadataField.getDefaulValue());
|
||||
wrapperObj.setFieldName(metadataField.getFieldName());
|
||||
wrapperObj.setIsBoolean(metadataField.getIsBoolean());
|
||||
wrapperObj.setMandatory(metadataField.getMandatory());
|
||||
wrapperObj.setNote(metadataField.getNote());
|
||||
for (MetadataType mt : reader.getListOfMetadataTypes()) {
|
||||
MetadataFormat metadata = reader.getMetadataFormatForMetadataType(mt);
|
||||
|
||||
MetadataValidator validator = metadataField.getValidator();
|
||||
if(validator != null)
|
||||
wrapperObj.setValidator(validator.getRegularExpression());
|
||||
// we need to wrap the list of metadata
|
||||
List<MetadataFieldWrapper> wrapperList = new ArrayList<MetadataFieldWrapper>();
|
||||
List<MetadataField> toWrap = metadata.getMetadataFields();
|
||||
for(MetadataField metadataField: toWrap){
|
||||
|
||||
MetadataVocabulary vocabulary = metadataField.getVocabulary();
|
||||
if(vocabulary != null)
|
||||
wrapperObj.setVocabulary(vocabulary.getVocabularyFields());
|
||||
MetadataFieldWrapper wrapperObj = new MetadataFieldWrapper();
|
||||
wrapperObj.setDefaulValue(metadataField.getDefaulValue());
|
||||
wrapperObj.setFieldName(metadataField.getFieldName());
|
||||
wrapperObj.setIsBoolean(metadataField.getIsBoolean());
|
||||
wrapperObj.setMandatory(metadataField.getMandatory());
|
||||
wrapperObj.setNote(metadataField.getNote());
|
||||
|
||||
// add to the list
|
||||
wrapperList.add(wrapperObj);
|
||||
MetadataValidator validator = metadataField.getValidator();
|
||||
if(validator != null)
|
||||
wrapperObj.setValidator(validator.getRegularExpression());
|
||||
|
||||
MetadataVocabulary vocabulary = metadataField.getVocabulary();
|
||||
if(vocabulary != null)
|
||||
wrapperObj.setVocabulary(vocabulary.getVocabularyFields());
|
||||
|
||||
// add to the list
|
||||
wrapperList.add(wrapperObj);
|
||||
|
||||
}
|
||||
|
||||
// wrap the mt as well
|
||||
MetaDataTypeWrapper typeWrapper = new MetaDataTypeWrapper();
|
||||
typeWrapper.setDescription(mt.getDescription());
|
||||
typeWrapper.setId(mt.getId());
|
||||
typeWrapper.setName(mt.getName());
|
||||
MetaDataProfileBean bean = new MetaDataProfileBean(typeWrapper, wrapperList);
|
||||
beans.add(bean);
|
||||
}
|
||||
|
||||
// wrap the mt as well
|
||||
MetaDataTypeWrapper typeWrapper = new MetaDataTypeWrapper();
|
||||
typeWrapper.setDescription(mt.getDescription());
|
||||
typeWrapper.setId(mt.getId());
|
||||
typeWrapper.setName(mt.getName());
|
||||
MetaDataProfileBean bean = new MetaDataProfileBean(typeWrapper, wrapperList);
|
||||
beans.add(bean);
|
||||
logger.debug("List of beans is " + beans);
|
||||
session.setAttribute(CKAN_PROFILES_KEY, beans);
|
||||
logger.debug("List of profiles has been saved into session");
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error while retrieving metadata beans ", e);
|
||||
}
|
||||
|
||||
logger.debug("List of beans is " + beans);
|
||||
return beans;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error while retrieving metadata beans ", e);
|
||||
}
|
||||
|
||||
return null;
|
||||
return beans;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LicensesBean getLicenses() {
|
||||
|
||||
logger.info("Request for CKAN licenses");
|
||||
try {
|
||||
List<String> titlesLicenses = getCkanUtilsObj().getLicenseTitles();
|
||||
// return the bean
|
||||
return new LicensesBean(titlesLicenses);
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to retrieve licenses", e);
|
||||
|
||||
ASLSession session = getASLSession();
|
||||
String username = session.getUsername();
|
||||
logger.debug("User in session is " + username);
|
||||
|
||||
LicensesBean licensesBean = null;
|
||||
if(session.getAttribute(CKAN_LICENSES_KEY) != null){
|
||||
licensesBean = (LicensesBean)session.getAttribute(CKAN_LICENSES_KEY);
|
||||
logger.debug("List of licenses was into session");
|
||||
}
|
||||
return null;
|
||||
else{
|
||||
List<String> titlesLicenses = getCkanUtilsObj().getLicenseTitles();
|
||||
licensesBean = new LicensesBean(titlesLicenses);
|
||||
session.setAttribute(CKAN_LICENSES_KEY, licensesBean);
|
||||
logger.debug("List of licenses has been saved into session");
|
||||
}
|
||||
|
||||
return licensesBean;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue