minor fix

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@129807 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-07-02 21:51:54 +00:00
parent 40b6bb2ad9
commit cd7ea087bf
1 changed files with 62 additions and 76 deletions

View File

@ -293,15 +293,12 @@ public class UserUtil {
try{ try{
String username = session.getUsername(); String username = session.getUsername();
logger.debug("User in session is " + username); logger.debug("User in session is " + username);
if(session.getAttribute(ckanLicensesKey) != null){
logger.debug("List of licenses was into session"); List<String> titlesLicenses = ckanUtils.getLicenseTitles();
} LicensesBean licensesBean = new LicensesBean(titlesLicenses);
else{ session.setAttribute(ckanLicensesKey, licensesBean);
List<String> titlesLicenses = ckanUtils.getLicenseTitles(); logger.info("List of licenses has been saved into session" + licensesBean);
LicensesBean licensesBean = new LicensesBean(titlesLicenses);
session.setAttribute(ckanLicensesKey, licensesBean);
logger.info("List of licenses has been saved into session" + licensesBean);
}
} }
catch(Exception e){ catch(Exception e){
logger.error("Failed to preload licenses list", e); logger.error("Failed to preload licenses list", e);
@ -323,37 +320,32 @@ public class UserUtil {
logger.debug("Request for user " + username + " organizations list"); logger.debug("Request for user " + username + " organizations list");
List<String> orgsName = new ArrayList<String>(); List<String> orgsName = new ArrayList<String>();
if(session.getAttribute(ckanOrganizationsPublishKey) != null){ if(ckanUtils.isSysAdmin(username, token)){
logger.debug("List of organizations was into session");
}
else{
if(ckanUtils.isSysAdmin(username, token)){
logger.info("The user " + username + " is a sysadmin. He can publish everywhere"); logger.info("The user " + username + " is a sysadmin. He can publish everywhere");
orgsName = ckanUtils.getOrganizationsNames(); // get all organizations' names orgsName = ckanUtils.getOrganizationsNames(); // get all organizations' names
}else{ }else{
// We need to retrieve orgs in which the user has the roles ADMIN or EDITOR // We need to retrieve orgs in which the user has the roles ADMIN or EDITOR
List<RolesIntoOrganization> rolesToMatch = new ArrayList<RolesIntoOrganization>(); List<RolesIntoOrganization> rolesToMatch = new ArrayList<RolesIntoOrganization>();
rolesToMatch.add(RolesIntoOrganization.EDITOR); rolesToMatch.add(RolesIntoOrganization.EDITOR);
rolesToMatch.add(RolesIntoOrganization.ADMIN); rolesToMatch.add(RolesIntoOrganization.ADMIN);
Map<String, List<RolesIntoOrganization>> orgsAndRoles = ckanUtils.getGroupsAndRolesByUser(username, rolesToMatch); Map<String, List<RolesIntoOrganization>> orgsAndRoles = ckanUtils.getGroupsAndRolesByUser(username, rolesToMatch);
logger.debug("Result is " + orgsAndRoles); logger.debug("Result is " + orgsAndRoles);
Iterator<Entry<String, List<RolesIntoOrganization>>> iterator = orgsAndRoles.entrySet().iterator(); Iterator<Entry<String, List<RolesIntoOrganization>>> iterator = orgsAndRoles.entrySet().iterator();
// get the names // get the names
while (iterator.hasNext()) { while (iterator.hasNext()) {
Map.Entry<String, List<RolesIntoOrganization>> entry = (Map.Entry<String, List<RolesIntoOrganization>>) iterator Map.Entry<String, List<RolesIntoOrganization>> entry = (Map.Entry<String, List<RolesIntoOrganization>>) iterator
.next(); .next();
orgsName.add(entry.getKey()); orgsName.add(entry.getKey());
logger.debug("The user has a role ADMIN/EDITOR into org " + entry.getKey()); logger.debug("The user has a role ADMIN/EDITOR into org " + entry.getKey());
}
} }
session.setAttribute(ckanOrganizationsPublishKey, orgsName);
logger.info("Organizations name for user " + username + " has been saved into session");
} }
session.setAttribute(ckanOrganizationsPublishKey, orgsName);
logger.info("Organizations name for user " + username + " has been saved into session");
}catch(Exception e){ }catch(Exception e){
logger.error("Failed to preload list of organizations in which the user can publish", e); logger.error("Failed to preload list of organizations in which the user can publish", e);
} }
@ -374,61 +366,55 @@ public class UserUtil {
String username = session.getUsername(); String username = session.getUsername();
logger.debug("User in session is " + username); logger.debug("User in session is " + username);
if(session.getAttribute(ckanProfilesKey) != null){ List<MetaDataProfileBean> beans = new ArrayList<MetaDataProfileBean>();
logger.info("List of profiles was into session");
}
else{
List<MetaDataProfileBean> beans = new ArrayList<MetaDataProfileBean>(); try {
try { DataCalogueMetadataFormatReader reader = new DataCalogueMetadataFormatReader();
DataCalogueMetadataFormatReader reader = new DataCalogueMetadataFormatReader(); for (MetadataType mt : reader.getListOfMetadataTypes()) {
MetadataFormat metadata = reader.getMetadataFormatForMetadataType(mt);
for (MetadataType mt : reader.getListOfMetadataTypes()) { // we need to wrap the list of metadata
MetadataFormat metadata = reader.getMetadataFormatForMetadataType(mt); List<MetadataFieldWrapper> wrapperList = new ArrayList<MetadataFieldWrapper>();
List<MetadataField> toWrap = metadata.getMetadataFields();
for(MetadataField metadataField: toWrap){
// we need to wrap the list of metadata MetadataFieldWrapper wrapperObj = new MetadataFieldWrapper();
List<MetadataFieldWrapper> wrapperList = new ArrayList<MetadataFieldWrapper>(); wrapperObj.setDefaulValue(metadataField.getDefaulValue());
List<MetadataField> toWrap = metadata.getMetadataFields(); wrapperObj.setFieldName(metadataField.getFieldName());
for(MetadataField metadataField: toWrap){ wrapperObj.setIsBoolean(metadataField.getIsBoolean());
wrapperObj.setMandatory(metadataField.getMandatory());
wrapperObj.setNote(metadataField.getNote());
MetadataFieldWrapper wrapperObj = new MetadataFieldWrapper(); MetadataValidator validator = metadataField.getValidator();
wrapperObj.setDefaulValue(metadataField.getDefaulValue()); if(validator != null)
wrapperObj.setFieldName(metadataField.getFieldName()); wrapperObj.setValidator(validator.getRegularExpression());
wrapperObj.setIsBoolean(metadataField.getIsBoolean());
wrapperObj.setMandatory(metadataField.getMandatory());
wrapperObj.setNote(metadataField.getNote());
MetadataValidator validator = metadataField.getValidator(); MetadataVocabulary vocabulary = metadataField.getVocabulary();
if(validator != null) if(vocabulary != null)
wrapperObj.setValidator(validator.getRegularExpression()); wrapperObj.setVocabulary(vocabulary.getVocabularyFields());
MetadataVocabulary vocabulary = metadataField.getVocabulary(); // add to the list
if(vocabulary != null) wrapperList.add(wrapperObj);
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);
} }
logger.info("List of beans is " + beans); // wrap the mt as well
session.setAttribute(ckanProfilesKey, beans); MetaDataTypeWrapper typeWrapper = new MetaDataTypeWrapper();
logger.debug("List of profiles has been saved into session"); typeWrapper.setDescription(mt.getDescription());
typeWrapper.setId(mt.getId());
} catch (Exception e) { typeWrapper.setName(mt.getName());
logger.error("Error while retrieving metadata beans ", e); MetaDataProfileBean bean = new MetaDataProfileBean(typeWrapper, wrapperList);
beans.add(bean);
} }
logger.info("List of beans is " + beans);
session.setAttribute(ckanProfilesKey, beans);
logger.debug("List of profiles has been saved into session");
} catch (Exception e) {
logger.error("Error while retrieving metadata beans ", e);
} }
} }
catch(Exception e){ catch(Exception e){