@ -28,13 +28,11 @@ import eu.eudat.exceptions.security.UnauthorisedException;
import eu.eudat.logic.builders.entity.UserInfoBuilder ;
import eu.eudat.logic.mapper.elastic.DmpMapper ;
import eu.eudat.logic.mapper.elastic.criteria.DmpCriteriaMapper ;
import eu.eudat.logic.proxy.config.DOIFunder ;
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader ;
import eu.eudat.logic.services.ApiContext ;
import eu.eudat.logic.services.forms.VisibilityRuleService ;
import eu.eudat.logic.services.forms.VisibilityRuleServiceImpl ;
import eu.eudat.logic.services.operations.DatabaseRepository ;
import eu.eudat.logic.services.utilities.UtilitiesService ;
import eu.eudat.logic.utilities.builders.XmlBuilder ;
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope ;
import eu.eudat.logic.utilities.documents.pdf.PDFUtils ;
@ -59,6 +57,8 @@ import eu.eudat.models.data.project.ProjectDMPEditorModel;
import eu.eudat.models.data.security.Principal ;
import eu.eudat.models.data.user.composite.PagedDatasetProfile ;
import eu.eudat.models.data.userinfo.UserListingModel ;
import eu.eudat.models.deposit.zenodo.ZenodoDeposit ;
import eu.eudat.models.deposit.zenodo.mapper.DMPToZenodoMapper ;
import eu.eudat.queryable.QueryableList ;
import eu.eudat.types.Authorities ;
import eu.eudat.types.MetricNames ;
@ -113,9 +113,10 @@ public class DataManagementPlanManager {
private RDAManager rdaManager ;
private UserManager userManager ;
private final MetricsManager metricsManager ;
private final ConfigLoader configLoader ;
@Autowired
public DataManagementPlanManager ( ApiContext apiContext , DatasetManager datasetManager , Environment environment , RDAManager rdaManager , UserManager userManager , MetricsManager metricsManager ) {
public DataManagementPlanManager ( ApiContext apiContext , DatasetManager datasetManager , Environment environment , RDAManager rdaManager , UserManager userManager , MetricsManager metricsManager , ConfigLoader configLoader ) {
this . apiContext = apiContext ;
this . datasetManager = datasetManager ;
this . databaseRepository = apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) ;
@ -123,6 +124,7 @@ public class DataManagementPlanManager {
this . rdaManager = rdaManager ;
this . userManager = userManager ;
this . metricsManager = metricsManager ;
this . configLoader = configLoader ;
}
/ *
@ -1055,7 +1057,7 @@ public class DataManagementPlanManager {
UserInfo user = apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getUserInfoDao ( ) . find ( principal . getId ( ) ) ;
sendNotification ( dmp , user , NotificationType . DMP_PUBLISH ) ;
if ( dmp . getDoi ( ) ! = null & & ! dmp . getDoi ( ) . isEmpty ( ) ) {
this . createZenodoDoi ( dmp . getId ( ) , principal , null, true) ;
this . createZenodoDoi ( dmp . getId ( ) , principal , true) ;
}
}
@ -2013,11 +2015,11 @@ public class DataManagementPlanManager {
}
}
public String createZenodoDoi ( UUID id , Principal principal , ConfigLoader configLoader ) throws Exception {
return this . createZenodoDoi ( id , principal , configLoader , false ) ;
public String createZenodoDoi ( UUID id , Principal principal ) throws Exception {
return this . createZenodoDoi ( id , principal , false ) ;
}
public String createZenodoDoi ( UUID id , Principal principal , ConfigLoader configLoader , boolean update ) throws Exception {
public String createZenodoDoi ( UUID id , Principal principal , boolean update ) throws Exception {
DMP dmp = this . apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getDmpDao ( ) . find ( id ) ;
if ( ! isUserOwnerOfDmp ( dmp , principal ) )
throw new Exception ( "User is not authorized to invoke this action" ) ;
@ -2039,129 +2041,18 @@ public class DataManagementPlanManager {
HttpHeaders headers = new HttpHeaders ( ) ;
headers . setAccept ( Collections . singletonList ( MediaType . APPLICATION_JSON ) ) ;
headers . setContentType ( MediaType . APPLICATION_JSON ) ;
String createData = null ;
Map < String , Object > extraProperties = dmp . getExtraProperties ( ) ! = null ? new org . json . JSONObject ( dmp . getExtraProperties ( ) ) . toMap ( ) : new HashMap < > ( ) ;
StringBuilder dataBuilder = new StringBuilder ( ) ;
dataBuilder . append ( "{\n \"metadata\": {\n" ) ;
dataBuilder . append ( " \"title\": \"" ) . append ( dmp . getLabel ( ) ) . append ( "\",\n" ) ;
dataBuilder . append ( " \"upload_type\": \"publication\",\n" ) ;
dataBuilder . append ( " \"publication_type\": \"datamanagementplan\",\n" ) ;
dataBuilder . append ( " \"description\": \"" ) . append ( ( dmp . getDescription ( ) ! = null & & ! dmp . getDescription ( ) . isEmpty ( ) ? dmp . getDescription ( ) : "<p></p>" ) ) . append ( "\",\n" ) ;
dataBuilder . append ( " \"version\": \"" ) . append ( dmp . getVersion ( ) ) . append ( "\",\n" ) ;
dataBuilder . append ( " \"communities\": [{\n \t\t\"identifier\": \"" ) . append ( environment . getProperty ( "zenodo.community" ) ) . append ( "\"\n \t\t}],\n" ) ;
dataBuilder . append ( " \"access_right\": \"" ) ;
if ( extraProperties . get ( "visible" ) = = null ) {
dataBuilder . append ( "restricted\",\n" ) ;
dataBuilder . append ( " \"access_conditions\": \"\",\n" ) ;
} else {
if ( ( ( Boolean ) extraProperties . get ( "visible" ) ) ) {
Instant publicationDate = Instant . parse ( extraProperties . get ( "publicDate" ) . toString ( ) ) ;
if ( publicationDate . isBefore ( Instant . now ( ) ) ) {
dataBuilder . append ( "open\",\n" ) ;
} else {
dataBuilder . append ( "embargoed\",\n" ) ;
dataBuilder . append ( " \"embargo_date\": \"" + publicationDate + "\",\n" ) ;
}
if ( extraProperties . get ( "license" ) ! = null ) {
dataBuilder . append ( " \"license\": \"" ) . append ( ( ( Map ) extraProperties . get ( "license" ) ) . get ( "pid" ) ) . append ( "\",\n" ) ;
}
} else {
dataBuilder . append ( "restricted\",\n" ) ;
dataBuilder . append ( " \"access_conditions\": \"\",\n" ) ;
}
}
if ( dmp . isPublic ( ) ) {
dataBuilder . append ( " \"related_identifiers\": [{\n" ) ;
dataBuilder . append ( " \t\t\"identifier\": \"" ) . append ( ( this . environment . getProperty ( "dmp.domain" ) + "/external/zenodo/" + id . toString ( ) ) ) . append ( "\",\n" ) ;
dataBuilder . append ( " \t\t\"relation\": \"isIdenticalTo\"}],\n" ) ;
}
dataBuilder . append ( " \"contributors\": [" ) ;
int i = 0 ;
for ( UserDMP userDMP : dmp . getUsers ( ) ) {
if ( i > 0 ) {
dataBuilder . append ( ",\n" ) ;
}
dataBuilder . append ( "{\n" ) ;
dataBuilder . append ( " \t\t\"name\": \"" ) . append ( userDMP . getUser ( ) . getName ( ) ) . append ( "\",\n" ) ;
dataBuilder . append ( " \t\t\"type\": \"" ) . append ( "ProjectMember" ) . append ( "\",\n" ) ;
if ( dmp . getOrganisations ( ) ! = null & & ! dmp . getOrganisations ( ) . isEmpty ( ) ) {
dataBuilder . append ( " \t\t\"affiliation\": \"" ) ;
int j = 0 ;
for ( Organisation organization : dmp . getOrganisations ( ) ) {
if ( j > 0 ) {
dataBuilder . append ( ", " ) ;
}
dataBuilder . append ( organization . getLabel ( ) ) ;
j + + ;
}
dataBuilder . append ( "\"\n}" ) ;
} else {
dataBuilder . append ( " \t\t\"affiliation\": \"" + this . environment . getProperty ( "zenodo.affiliation" ) + "\"\n}" ) ;
}
i + + ;
}
for ( Researcher researcher : dmp . getResearchers ( ) ) {
if ( i > 0 ) {
dataBuilder . append ( ",\n" ) ;
}
dataBuilder . append ( "{\n" ) ;
dataBuilder . append ( " \t\t\"name\": \"" ) . append ( researcher . getLabel ( ) ) . append ( "\",\n" ) ;
dataBuilder . append ( " \t\t\"type\": \"" ) . append ( "Researcher" ) . append ( "\",\n" ) ;
String referenceHead = researcher . getReference ( ) . split ( ":" ) [ 0 ] ;
String referenceTail = researcher . getReference ( ) . replace ( referenceHead + ":" , "" ) ;
dataBuilder . append ( " \t\t\"affiliation\": \"" + referenceHead + "\"" ) ;
if ( referenceHead . toUpperCase ( ) . equals ( "ORCID" ) ) {
dataBuilder . append ( ",\n \t\t\"orcid\": \"" + referenceTail + "\"" ) ;
}
dataBuilder . append ( "\n}" ) ;
i + + ;
}
dataBuilder . append ( "],\n" ) ;
if ( dmp . getGrant ( ) . getReference ( ) = = null ) {
dmp . getGrant ( ) . setReference ( "dmp:" + dmp . getGrant ( ) . getId ( ) ) ;
}
String grantReferenceHead = dmp . getGrant ( ) . getReference ( ) . split ( ":" ) [ 0 ] ;
if ( grantReferenceHead . equals ( "openaire" ) ) {
String grantReferenceTail = dmp . getGrant ( ) . getReference ( ) . split ( ":" ) [ 3 ] ;
DOIFunder doiFunder = configLoader . getDOIFunders ( ) . stream ( )
. filter ( doiFunder1 - > dmp . getGrant ( ) . getFunder ( ) . getLabel ( ) . contains ( doiFunder1 . getFunder ( ) ) | | doiFunder1 . getFunder ( ) . contains ( dmp . getGrant ( ) . getFunder ( ) . getLabel ( ) ) )
. findFirst ( ) . orElse ( null ) ;
if ( doiFunder ! = null ) {
String finalId = doiFunder . getDOI ( ) + "::" + grantReferenceTail ;
dataBuilder . append ( " \"grants\": [{\n" ) ;
dataBuilder . append ( " \t\t\"id\": \"" ) . append ( finalId ) . append ( "\"\n}],\n" ) ;
}
}
dataBuilder . append ( " \"creators\": [{\n" ) ;
dataBuilder . append ( " \t\t\"name\": \"" ) . append ( dmp . getUsers ( ) . stream ( ) . filter ( userDMP - > userDMP . getRole ( ) . equals ( UserDMP . UserDMPRoles . OWNER . getValue ( ) ) ) . findFirst ( ) . get ( ) . getUser ( ) . getName ( ) ) . append ( "\",\n" ) ;
if ( dmp . getOrganisations ( ) ! = null & & ! dmp . getOrganisations ( ) . isEmpty ( ) ) {
dataBuilder . append ( " \t\t\"affiliation\": \"" ) ;
int j = 0 ;
for ( Organisation organization : dmp . getOrganisations ( ) ) {
if ( j > 0 ) {
dataBuilder . append ( ", " ) ;
}
dataBuilder . append ( organization . getLabel ( ) ) ;
j + + ;
}
dataBuilder . append ( "\"}]\n" ) ;
} else {
dataBuilder . append ( " \t\t\"affiliation\": \"" + this . environment . getProperty ( "zenodo.affiliation" ) + "\"}]\n" ) ;
}
dataBuilder . append ( " }\n" ) . append ( "}" ) ;
createData = dataBuilder . toString ( ) ;
/ * ObjectMapper mapper = new ObjectMapper ( ) ;
mapper . configure ( JsonParser . Feature . ALLOW_UNQUOTED_CONTROL_CHARS , true ) ;
JsonNode createDataJSON = mapper . readTree ( createData ) ; * /
HttpEntity < String > request = new HttpEntity < > ( createData , headers ) ;
Map createResponse = null ;
LinkedHashMap < String , String > links = null ;
ZenodoDeposit deposit = DMPToZenodoMapper . fromDMP ( dmp , environment , configLoader ) ;
//if (Objects.requireNonNull(environment.getProperty("spring.profiles.active")).contains("devel")) {
String json = objectMapper . writerWithDefaultPrettyPrinter ( ) . writeValueAsString ( deposit ) ;
logger . info ( json ) ;
//}
HttpEntity < ZenodoDeposit > request = new HttpEntity < > ( deposit , headers ) ;
Map createResponse ;
LinkedHashMap < String , String > links ;
String previousDOI = this . getPreviousDOI ( dmp . getGroupId ( ) , dmp . getId ( ) ) ;
String unpublishedUrl = null ;
String publishUrl = null ;
String finalDoi = null ;
String publishUrl ;
String finalDoi ;
try {
if ( previousDOI = = null ) {