task9462 #18
|
@ -27,6 +27,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import eu.dnetlib.openaire.common.AbstractExporterController;
|
||||
import eu.dnetlib.openaire.community.model.DepositionInfo;
|
||||
import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
|
||||
import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
|
||||
import eu.dnetlib.openaire.exporter.model.community.CommunityContentprovider;
|
||||
|
@ -328,6 +329,27 @@ public class CommunityApiController extends AbstractExporterController {
|
|||
}
|
||||
}
|
||||
|
||||
@PostMapping("/community/{id}/datasources/deposit")
|
||||
@Operation(summary = "associate a content provider to the community", description = "associate a content provider to the community", tags = {
|
||||
C_CP, W
|
||||
})
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "not found"),
|
||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||
})
|
||||
public CommunityContentprovider addCommunityContentprovider(
|
||||
@PathVariable final String id,
|
||||
@RequestBody final DepositionInfo info) throws CommunityException {
|
||||
try {
|
||||
return communityService.updateCommunityDatasourcesDeposit(id, info.getOpenaireId(), info.getDeposit(), info.getMessage());
|
||||
} catch (final ResourceNotFoundException e) {
|
||||
throw e;
|
||||
} catch (final Throwable e) {
|
||||
throw new CommunityException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping({ "/community/{id}/contentproviders", "/community/{id}/datasources" })
|
||||
@Operation(summary = "remove the association between a content provider and the community", description = "remove the association between a content provider and the community", tags = {
|
||||
C_CP, W
|
||||
|
|
|
@ -219,6 +219,18 @@ public class CommunityService {
|
|||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public CommunityContentprovider updateCommunityDatasourcesDeposit(final String id, final String dsId, final Boolean deposit, final String message) {
|
||||
return dbDatasourceRepository.findById(new DbDatasourcePK(id, dsId))
|
||||
.map(ds -> {
|
||||
ds.setDeposit(deposit != null ? deposit : false);
|
||||
ds.setMessage(message);
|
||||
return ds;
|
||||
})
|
||||
.map(CommunityMappingUtils::toCommunityContentprovider)
|
||||
.orElseThrow(() -> new ResourceNotFoundException("Community and/or Datasource not found"));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void addCommunityDatasources(final String id, final CommunityContentprovider... contentproviders) {
|
||||
final List<DbDatasource> list = Arrays.stream(contentproviders)
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package eu.dnetlib.openaire.community.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class DepositionInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 7538663287451167904L;
|
||||
|
||||
private String openaireId;
|
||||
|
||||
private Boolean deposit;
|
||||
|
||||
private String message;
|
||||
|
||||
public String getOpenaireId() {
|
||||
return openaireId;
|
||||
}
|
||||
|
||||
public void setOpenaireId(final String openaireId) {
|
||||
this.openaireId = openaireId;
|
||||
}
|
||||
|
||||
public Boolean getDeposit() {
|
||||
return deposit;
|
||||
}
|
||||
|
||||
public void setDeposit(final Boolean deposit) {
|
||||
this.deposit = deposit;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(final String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue