new_model_for_communities #15

Merged
michele.artini merged 81 commits from new_model_for_communities into master 2023-10-24 08:12:26 +02:00
5 changed files with 103 additions and 52 deletions
Showing only changes of commit e87267e9e5 - Show all commits

View File

@ -50,6 +50,7 @@ import eu.dnetlib.openaire.exporter.model.community.CommunitySummary;
import eu.dnetlib.openaire.exporter.model.community.CommunityWritableProperties;
import eu.dnetlib.openaire.exporter.model.community.SubCommunity;
import eu.dnetlib.openaire.exporter.model.community.selectioncriteria.SelectionCriteria;
import eu.dnetlib.openaire.exporter.model.context.IISConfigurationEntry;
@Service
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
@ -591,4 +592,24 @@ public class CommunityService {
dbCommunityRepository.deleteById(id);
}
@Transactional
public List<IISConfigurationEntry> getIISConfiguration(final String id) throws CommunityException {
try {
final List<IISConfigurationEntry> res = new ArrayList<>();
res.add(dbCommunityRepository.findById(id)
.map(CommunityMappingUtils::asIISConfigurationEntry)
.orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id)));
for (final DbSubCommunity subc : dbSubCommunityRepository.findByCommunity(id)) {
res.add(CommunityMappingUtils.asIISConfigurationEntry(subc));
}
return res;
} catch (final Throwable e) {
log.error(e);
throw new CommunityException(e);
}
}
}

View File

@ -50,55 +50,55 @@ import eu.dnetlib.openaire.exporter.model.context.Param;
public class CommunityImporterService {
// common
private final static String OPENAIRE_ID = "openaireId";
private final static String PIPE_SEPARATOR = "||";
private final static String ID_SEPARATOR = "::";
private final static String CSV_DELIMITER = ",";
private final static String CLABEL = "label";
public final static String OPENAIRE_ID = "openaireId";
public final static String PIPE_SEPARATOR = "||";
public final static String ID_SEPARATOR = "::";
public final static String CSV_DELIMITER = ",";
public final static String CLABEL = "label";
// id suffixes
private final static String PROJECTS_ID_SUFFIX = ID_SEPARATOR + "projects";
private final static String CONTENTPROVIDERS_ID_SUFFIX = ID_SEPARATOR + "contentproviders";
private final static String ZENODOCOMMUNITY_ID_SUFFIX = ID_SEPARATOR + "zenodocommunities";
private final static String ORGANIZATION_ID_SUFFIX = ID_SEPARATOR + "organizations";
public final static String PROJECTS_ID_SUFFIX = ID_SEPARATOR + "projects";
public final static String CONTENTPROVIDERS_ID_SUFFIX = ID_SEPARATOR + "contentproviders";
public final static String ZENODOCOMMUNITY_ID_SUFFIX = ID_SEPARATOR + "zenodocommunities";
public final static String ORGANIZATION_ID_SUFFIX = ID_SEPARATOR + "organizations";
// community summary
private final static String CSUMMARY_DESCRIPTION = "description";
private final static String CSUMMARY_LOGOURL = "logourl";
private final static String CSUMMARY_STATUS = "status";
private final static String CSUMMARY_NAME = "name";
private final static String CSUMMARY_MANAGER = "manager";
private final static String CSUMMARY_ZENODOC = "zenodoCommunity";
public final static String CSUMMARY_DESCRIPTION = "description";
public final static String CSUMMARY_LOGOURL = "logourl";
public final static String CSUMMARY_STATUS = "status";
public final static String CSUMMARY_NAME = "name";
public final static String CSUMMARY_MANAGER = "manager";
public final static String CSUMMARY_ZENODOC = "zenodoCommunity";
// community profile
private final static String CPROFILE_SUBJECT = "subject";
private final static String CPROFILE_CREATIONDATE = "creationdate";
private final static String CPROFILE_FOS = "fos";
private final static String CPROFILE_SDG = "sdg";
private final static String CPROFILE_ADVANCED_CONSTRAINT = "advancedConstraints";
private final static String CPROFILE_REMOVE_CONSTRAINT = "removeConstraints";
private final static String CPROFILE_SUGGESTED_ACKNOWLEDGEMENT = "suggestedAcknowledgement";
public final static String CPROFILE_SUBJECT = "subject";
public final static String CPROFILE_CREATIONDATE = "creationdate";
public final static String CPROFILE_FOS = "fos";
public final static String CPROFILE_SDG = "sdg";
public final static String CPROFILE_ADVANCED_CONSTRAINT = "advancedConstraints";
public final static String CPROFILE_REMOVE_CONSTRAINT = "removeConstraints";
public final static String CPROFILE_SUGGESTED_ACKNOWLEDGEMENT = "suggestedAcknowledgement";
// community project
private final static String CPROJECT_FUNDER = "funder";
private final static String CPROJECT_NUMBER = "CD_PROJECT_NUMBER";
private final static String CPROJECT_FULLNAME = "projectfullname";
private final static String CPROJECT_ACRONYM = "acronym";
public final static String CPROJECT_FUNDER = "funder";
public final static String CPROJECT_NUMBER = "CD_PROJECT_NUMBER";
public final static String CPROJECT_FULLNAME = "projectfullname";
public final static String CPROJECT_ACRONYM = "acronym";
// community content provider
private final static String CCONTENTPROVIDER_NAME = "name";
private final static String CCONTENTPROVIDER_OFFICIALNAME = "officialname";
private final static String CCONTENTPROVIDER_ENABLED = "enabled";
private final static String CCONTENTPROVIDERENABLED_DEFAULT = "true";
private final static String CCONTENTPROVIDER_SELCRITERIA = "selcriteria";
public final static String CCONTENTPROVIDER_NAME = "name";
public final static String CCONTENTPROVIDER_OFFICIALNAME = "officialname";
public final static String CCONTENTPROVIDER_ENABLED = "enabled";
public final static String CCONTENTPROVIDERENABLED_DEFAULT = "true";
public final static String CCONTENTPROVIDER_SELCRITERIA = "selcriteria";
// community zenodo community
private final static String CZENODOCOMMUNITY_ID = "zenodoid";
public final static String CZENODOCOMMUNITY_ID = "zenodoid";
// community organization
private final static String CORGANIZATION_NAME = "name";
private final static String CORGANIZATION_LOGOURL = "logourl";
private final static String CORGANIZATION_WEBSITEURL = "websiteurl";
public final static String CORGANIZATION_NAME = "name";
public final static String CORGANIZATION_LOGOURL = "logourl";
public final static String CORGANIZATION_WEBSITEURL = "websiteurl";
@Autowired
private DbOrganizationRepository dbOrganizationRepository;

View File

@ -15,6 +15,7 @@ import org.apache.commons.logging.LogFactory;
import com.google.common.collect.Lists;
import eu.dnetlib.openaire.community.importer.CommunityImporterService;
import eu.dnetlib.openaire.community.model.DbCommunity;
import eu.dnetlib.openaire.community.model.DbDatasource;
import eu.dnetlib.openaire.community.model.DbProject;
@ -27,6 +28,7 @@ import eu.dnetlib.openaire.exporter.model.community.CommunityProject;
import eu.dnetlib.openaire.exporter.model.community.CommunitySummary;
import eu.dnetlib.openaire.exporter.model.community.CommunityWritableProperties;
import eu.dnetlib.openaire.exporter.model.community.SubCommunity;
import eu.dnetlib.openaire.exporter.model.context.IISConfigurationEntry;
public class CommunityMappingUtils {
@ -252,4 +254,32 @@ public class CommunityMappingUtils {
return list != null ? list.toArray(new String[list.size()]) : new String[0];
}
public static IISConfigurationEntry asIISConfigurationEntry(final DbCommunity c) {
final IISConfigurationEntry conf = new IISConfigurationEntry();
conf.setId(c.getId());
conf.setLabel(c.getName());
conf.addParams(CommunityImporterService.CSUMMARY_DESCRIPTION, c.getDescription());
conf.addParams(CommunityImporterService.CSUMMARY_LOGOURL, c.getLogoUrl());
conf.addParams(CommunityImporterService.CSUMMARY_STATUS, c.getStatus().toString());
conf.addParams(CommunityImporterService.CSUMMARY_NAME, c.getName());
conf.addParams(CommunityImporterService.CSUMMARY_ZENODOC, c.getMainZenodoCommunity());
conf.addParams(CommunityImporterService.CPROFILE_SUBJECT, c.getSubjects());
conf.addParams(CommunityImporterService.CPROFILE_FOS, c.getFos());
conf.addParams(CommunityImporterService.CPROFILE_SDG, c.getSdg());
conf.addParams(CommunityImporterService.CPROFILE_ADVANCED_CONSTRAINT, c.getAdvancedConstraints() != null ? c.getAdvancedConstraints().toJson() : null);
conf.addParams(CommunityImporterService.CPROFILE_REMOVE_CONSTRAINT, c.getRemoveConstraints() != null ? c.getRemoveConstraints().toJson() : null);
conf.addParams(CommunityImporterService.CPROFILE_SUGGESTED_ACKNOWLEDGEMENT, c.getSuggestedAcknowledgements());
conf.addParams(CommunityImporterService.CPROFILE_CREATIONDATE, c.getCreationDate() != null ? c.getCreationDate().toString() : null);
return conf;
}
public static IISConfigurationEntry asIISConfigurationEntry(final DbSubCommunity subc) {
final IISConfigurationEntry conf = new IISConfigurationEntry();
conf.setId(subc.getId());
conf.setLabel(subc.getLabel());
if (subc.getParams() != null) {
conf.getParams().addAll(subc.getParams());
}
return conf;
}
}

View File

@ -1,6 +1,5 @@
package eu.dnetlib.openaire.context;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
@ -109,19 +108,8 @@ public class ContextApiController extends AbstractDnetController {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public List<IISConfigurationEntry> getIISConfiguration(
@PathVariable final String contextId) throws CommunityException {
try {
// TODO, see ticket https://support.openaire.eu/issues/9019
// ritornare le informazioni solo dei context (root) e delle subCommunities
final List<IISConfigurationEntry> res = new ArrayList<>();
return res;
} catch (final Throwable e) {
log.error(e);
throw new CommunityException(e);
}
public List<IISConfigurationEntry> getIISConfiguration(@PathVariable final String contextId) throws CommunityException {
return communityService.getIISConfiguration(contextId);
}
@RequestMapping(value = "/context/category/{categoryId}", produces = {

View File

@ -4,13 +4,15 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
public class IISConfigurationEntry implements Serializable {
private static final long serialVersionUID = -1470248262314248937L;
private String id;
private String label;
private List<String> params = new ArrayList<>();
private List<Param> params = new ArrayList<>();
public String getId() {
return id;
@ -28,12 +30,22 @@ public class IISConfigurationEntry implements Serializable {
this.label = label;
}
public List<String> getParams() {
public List<Param> getParams() {
return params;
}
public void setParams(final List<String> params) {
public void setParams(final List<Param> params) {
this.params = params;
}
public void addParams(final String name, final String... values) {
if (StringUtils.isNoneBlank(name) && values != null) {
for (final String v : values) {
if (StringUtils.isNotBlank(v)) {
params.add(new Param().setName(name).setValue(v));
}
}
}
}
}