partial implementation
This commit is contained in:
parent
fa84a3b90d
commit
8b7cc375fe
|
@ -28,6 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
|
||||
import eu.dnetlib.openaire.common.AbstractExporterController;
|
||||
import eu.dnetlib.openaire.community.model.DepositionInfo;
|
||||
import eu.dnetlib.openaire.community.utils.CommunityMappingUtils;
|
||||
import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
|
||||
import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
|
||||
import eu.dnetlib.openaire.exporter.model.community.CommunityContentprovider;
|
||||
|
@ -141,10 +142,10 @@ public class CommunityApiController extends AbstractExporterController {
|
|||
@ApiResponse(responseCode = "404", description = "not found"),
|
||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||
})
|
||||
public void deleteCommunity(@PathVariable final String id, @RequestParam(required = false, defaultValue = "false") final boolean recursive)
|
||||
public void deleteCommunity(@PathVariable final String id)
|
||||
throws CommunityException {
|
||||
try {
|
||||
communityService.deleteCommunity(id, recursive);
|
||||
communityService.removeCommunities(id);
|
||||
} catch (final ResourceNotFoundException e) {
|
||||
throw e;
|
||||
} catch (final Throwable e) {
|
||||
|
@ -1008,7 +1009,12 @@ public class CommunityApiController extends AbstractExporterController {
|
|||
@PathVariable final String id,
|
||||
@RequestBody final SubCommunity subcommunity) throws CommunityException {
|
||||
try {
|
||||
communityService.addSubCommunities(id, subcommunity);
|
||||
if (!id.equals(CommunityMappingUtils.calculateMainCommunityId(subcommunity.getSubCommunityId()))) {
|
||||
throw new CommunityException("The sub-collection id does not start with " + id);
|
||||
}
|
||||
|
||||
communityService.addSubCommunities(subcommunity);
|
||||
|
||||
return subcommunity;
|
||||
} catch (final ResourceNotFoundException e) {
|
||||
throw e;
|
||||
|
@ -1030,8 +1036,13 @@ public class CommunityApiController extends AbstractExporterController {
|
|||
@PathVariable final String id,
|
||||
@RequestBody final SubCommunity[] subcommunities) throws CommunityException {
|
||||
|
||||
for (final SubCommunity sub : subcommunities) {
|
||||
if (!id.equals(CommunityMappingUtils.calculateMainCommunityId(sub.getSubCommunityId()))) {
|
||||
throw new CommunityException("The sub-collection id does not start with " + id);
|
||||
}
|
||||
}
|
||||
try {
|
||||
communityService.addSubCommunities(id, subcommunities);
|
||||
communityService.addSubCommunities(subcommunities);
|
||||
return subcommunities;
|
||||
} catch (final ResourceNotFoundException e) {
|
||||
throw e;
|
||||
|
@ -1053,7 +1064,11 @@ public class CommunityApiController extends AbstractExporterController {
|
|||
@PathVariable final String id,
|
||||
@RequestParam final String subCommunityId) throws CommunityException {
|
||||
try {
|
||||
communityService.removeSubCommunities(id, subCommunityId);
|
||||
if (!id.equals(CommunityMappingUtils.calculateMainCommunityId(subCommunityId))) {
|
||||
throw new CommunityException("The sub-collection id does not start with " + id);
|
||||
}
|
||||
|
||||
communityService.removeCommunities(subCommunityId);
|
||||
} catch (final ResourceNotFoundException e) {
|
||||
throw e;
|
||||
} catch (final Throwable e) {
|
||||
|
@ -1074,7 +1089,12 @@ public class CommunityApiController extends AbstractExporterController {
|
|||
@PathVariable final String id,
|
||||
@RequestBody final String[] subCommunityIdList) throws CommunityException {
|
||||
try {
|
||||
communityService.removeSubCommunities(id, subCommunityIdList);
|
||||
for (final String sub : subCommunityIdList) {
|
||||
if (!id.equals(CommunityMappingUtils.calculateMainCommunityId(sub))) {
|
||||
throw new CommunityException("The sub-collection id does not start with " + id);
|
||||
}
|
||||
}
|
||||
communityService.removeCommunities(subCommunityIdList);
|
||||
} catch (final ResourceNotFoundException e) {
|
||||
throw e;
|
||||
} catch (final Throwable e) {
|
||||
|
|
|
@ -70,7 +70,7 @@ public class CommunityService {
|
|||
private static final Log log = LogFactory.getLog(CommunityService.class);
|
||||
|
||||
public List<CommunitySummary> listCommunities() {
|
||||
return dbCommunityRepository.findAll()
|
||||
return dbCommunityRepository.findByParentIsNull()
|
||||
.stream()
|
||||
.map(CommunityMappingUtils::toCommunitySummary)
|
||||
.collect(Collectors.toList());
|
||||
|
@ -269,25 +269,19 @@ public class CommunityService {
|
|||
dbSupportOrgRepository.saveAll(list);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void removeSubCommunities(final String masterId, final String... subCommunityIds) {
|
||||
for (final String subId : subCommunityIds) {
|
||||
dbCommunityRepository.deleteByMasterAndId(masterId, subId);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<SubCommunity> getSubCommunities(final String id) {
|
||||
return dbCommunityRepository.findByMaster(id)
|
||||
return dbCommunityRepository.findByIdStartsWith(id + CommunityMappingUtils.COMMUNITY_ID_PARTS_SEPARATOR)
|
||||
.stream()
|
||||
.map(CommunityMappingUtils::toSubCommunity)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void addSubCommunities(final String id, final SubCommunity... subs) {
|
||||
public void addSubCommunities(final SubCommunity... subs) {
|
||||
|
||||
final List<DbCommunity> list = Arrays.stream(subs)
|
||||
.map(s -> CommunityMappingUtils.toDbCommunity(id, s))
|
||||
.map(CommunityMappingUtils::toDbCommunity)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
dbCommunityRepository.saveAll(list);
|
||||
|
@ -443,15 +437,10 @@ public class CommunityService {
|
|||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteCommunity(final String id, final boolean recursive) {
|
||||
if (recursive) {
|
||||
dbProjectRepository.deleteByCommunity(id);
|
||||
dbDatasourceRepository.deleteByCommunity(id);
|
||||
dbOrganizationRepository.deleteByCommunity(id);
|
||||
dbSupportOrgRepository.deleteByCommunity(id);
|
||||
dbCommunityRepository.deleteByMaster(id);
|
||||
public void removeCommunities(final String... ids) {
|
||||
for (final String subId : ids) {
|
||||
dbCommunityRepository.deleteById(subId);
|
||||
}
|
||||
dbCommunityRepository.deleteById(id);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
@ -462,7 +451,7 @@ public class CommunityService {
|
|||
.map(CommunityMappingUtils::asIISConfigurationEntry)
|
||||
.orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id)));
|
||||
|
||||
for (final DbCommunity subc : dbCommunityRepository.findByMaster(id)) {
|
||||
for (final DbCommunity subc : dbCommunityRepository.findByIdStartsWith(id + CommunityMappingUtils.COMMUNITY_ID_PARTS_SEPARATOR)) {
|
||||
res.add(CommunityMappingUtils.asIISConfigurationEntry(subc));
|
||||
}
|
||||
|
||||
|
|
|
@ -216,7 +216,7 @@ public class CommunityImporterService {
|
|||
service.addCommunityProjects(context.getId(), projects.toArray(new CommunityProject[projects.size()]));
|
||||
service.addCommunityDatasources(context.getId(), datasources.toArray(new CommunityContentprovider[datasources.size()]));
|
||||
service.addCommunityOrganizations(context.getId(), orgs.toArray(new CommunityOrganization[orgs.size()]));
|
||||
service.addSubCommunities(context.getId(), subs.toArray(new SubCommunity[subs.size()]));
|
||||
service.addSubCommunities(subs.toArray(new SubCommunity[subs.size()]));
|
||||
} catch (
|
||||
|
||||
final Exception e) {
|
||||
|
|
|
@ -50,8 +50,8 @@ public class DbCommunity implements Serializable {
|
|||
@Column(name = "id")
|
||||
private String id;
|
||||
|
||||
@Column(name = "master")
|
||||
private String master;
|
||||
@Column(name = "parent")
|
||||
private String parent;
|
||||
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
@ -152,12 +152,12 @@ public class DbCommunity implements Serializable {
|
|||
this.id = id;
|
||||
}
|
||||
|
||||
public String getMaster() {
|
||||
return master;
|
||||
public String getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setMaster(final String master) {
|
||||
this.master = master;
|
||||
public void setParent(final String parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
|
|
@ -11,13 +11,15 @@ import eu.dnetlib.openaire.community.model.DbCommunity;
|
|||
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
|
||||
public interface DbCommunityRepository extends JpaRepository<DbCommunity, String> {
|
||||
|
||||
List<DbCommunity> findByParentIsNull();
|
||||
|
||||
@Query(value = "select id from communities where ?1 = ANY(array_append(other_zenodo_communities, main_zenodo_community))", nativeQuery = true)
|
||||
List<String> findByZenodoId(String zenodoId);
|
||||
|
||||
void deleteByMaster(String master);
|
||||
// TODO RICONTROLLARE QUERY
|
||||
|
||||
void deleteByMasterAndId(String masterId, String subId);
|
||||
void deleteByIdStartWith(String main);
|
||||
|
||||
List<DbCommunity> findByMaster(String master);
|
||||
List<DbCommunity> findByIdStartsWith(String prefix);
|
||||
|
||||
}
|
||||
|
|
|
@ -32,6 +32,8 @@ import eu.dnetlib.openaire.exporter.model.context.IISConfigurationEntry;
|
|||
|
||||
public class CommunityMappingUtils {
|
||||
|
||||
public static final String COMMUNITY_ID_PARTS_SEPARATOR = "::";
|
||||
|
||||
public final static String PIPE_SEPARATOR = "||";
|
||||
|
||||
private static final List<String> DATE_PATTERN = Lists.newArrayList("yyyy-MM-dd'T'hh:mm:ss", "yyyy-MM-dd'T'hh:mm:ssXXX", "yyyy-MM-dd'T'hh:mm:ss+00:00");
|
||||
|
@ -234,15 +236,11 @@ public class CommunityMappingUtils {
|
|||
return dbo;
|
||||
}
|
||||
|
||||
public static DbCommunity toDbCommunity(final String master, final SubCommunity sub) {
|
||||
public static DbCommunity toDbCommunity(final SubCommunity sub) {
|
||||
final DbCommunity dbsc = new DbCommunity();
|
||||
|
||||
dbsc.setId(sub.getSubCommunityId());
|
||||
dbsc.setMaster(master);
|
||||
|
||||
// TODO
|
||||
// dbsc.setParent(sub.getParent());
|
||||
|
||||
dbsc.setParent(sub.getParent());
|
||||
dbsc.setCategory(sub.getCategory());
|
||||
dbsc.setName(sub.getLabel());
|
||||
dbsc.setShortName(sub.getLabel());
|
||||
|
@ -266,11 +264,8 @@ public class CommunityMappingUtils {
|
|||
final SubCommunity sc = new SubCommunity();
|
||||
|
||||
sc.setSubCommunityId(sub.getId());
|
||||
sc.setCommunityId(sub.getMaster());
|
||||
|
||||
// TODO
|
||||
// sc.setParent(sub.getParent());
|
||||
|
||||
sc.setCommunityId(calculateMainCommunityId(sub.getId()));
|
||||
sc.setParent(sub.getParent());
|
||||
sc.setCategory(sub.getCategory());
|
||||
sc.setLabel(sub.getName());
|
||||
sc.setParams(sub.getParams());
|
||||
|
@ -288,6 +283,10 @@ public class CommunityMappingUtils {
|
|||
return sc;
|
||||
}
|
||||
|
||||
public static String calculateMainCommunityId(final String sub) {
|
||||
return StringUtils.substringBefore(sub, COMMUNITY_ID_PARTS_SEPARATOR);
|
||||
}
|
||||
|
||||
public static LocalDateTime asLocalDateTime(final String s) {
|
||||
if (StringUtils.isBlank(s)) { return null; }
|
||||
|
||||
|
@ -316,7 +315,7 @@ public class CommunityMappingUtils {
|
|||
conf.setId(c.getId());
|
||||
conf.setLabel(c.getName());
|
||||
|
||||
if (c.getMaster() == null) {
|
||||
if (c.getParent() == null) {
|
||||
conf.addParams(CommunityImporterService.CSUMMARY_DESCRIPTION, c.getDescription());
|
||||
conf.addParams(CommunityImporterService.CSUMMARY_LOGOURL, c.getLogoUrl());
|
||||
conf.addParams(CommunityImporterService.CSUMMARY_STATUS, c.getStatus().toString());
|
||||
|
|
Loading…
Reference in New Issue