@ -481,6 +481,7 @@ public class DataManagementPlanManager {
checkDmpValidationRules ( newDmp ) ;
}
UserInfo user = apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getUserInfoDao ( ) . find ( principal . getId ( ) ) ;
newDmp . setCreator ( user ) ;
createOrganisationsIfTheyDontExist ( newDmp , apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getOrganisationDao ( ) ) ;
createResearchersIfTheyDontExist ( newDmp , apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getResearcherDao ( ) , user ) ;
@ -645,6 +646,7 @@ public class DataManagementPlanManager {
if ( latestVersionDMP . get ( 0 ) . getVersion ( ) . equals ( oldDmp . getVersion ( ) ) ) {
DMP newDmp = dataManagementPlan . toDataModel ( ) ;
UserInfo user = apiContext . getOperationsContext ( ) . getBuilderFactory ( ) . getBuilder ( UserInfoBuilder . class ) . id ( principal . getId ( ) ) . build ( ) ;
newDmp . setCreator ( user ) ;
createOrganisationsIfTheyDontExist ( newDmp , databaseRepository . getOrganisationDao ( ) ) ;
createResearchersIfTheyDontExist ( newDmp , databaseRepository . getResearcherDao ( ) , user ) ;
@ -705,6 +707,7 @@ public class DataManagementPlanManager {
DMP newDmp = dataManagementPlan . toDataModel ( ) ;
UserInfo user = apiContext . getOperationsContext ( ) . getBuilderFactory ( ) . getBuilder ( UserInfoBuilder . class ) . id ( principal . getId ( ) ) . build ( ) ;
newDmp . setCreator ( user ) ;
createOrganisationsIfTheyDontExist ( newDmp , databaseRepository . getOrganisationDao ( ) ) ;
createResearchersIfTheyDontExist ( newDmp , databaseRepository . getResearcherDao ( ) , user ) ;
@ -1064,9 +1067,6 @@ public class DataManagementPlanManager {
} ) ;
UserInfo user = apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getUserInfoDao ( ) . find ( principal . getId ( ) ) ;
sendNotification ( dmp , user , NotificationType . DMP_PUBLISH ) ;
// if (dmp.getDois() != null && !dmp.getDois().isEmpty()) {
// this.createZenodoDoi(dmp.getId(), principal, true);
// }
}
@Transactional
@ -1456,6 +1456,40 @@ public class DataManagementPlanManager {
}
dmpElement . appendChild ( dmpProfileElement ) ;
Element dmpContactElement = xmlDoc . createElement ( "contact" ) ;
Element dmpContactName = xmlDoc . createElement ( "name" ) ;
Element dmpContactEmail = xmlDoc . createElement ( "email" ) ;
if ( dmp . getCreator ( ) ! = null ) {
dmpContactName . setTextContent ( dmp . getCreator ( ) . getName ( ) ) ;
dmpContactEmail . setTextContent ( dmp . getCreator ( ) . getEmail ( ) ) ;
}
else {
Iterator < UserDMP > users = dmp . getUsers ( ) . iterator ( ) ;
if ( users . hasNext ( ) ) {
UserDMP creator = users . next ( ) ;
dmpContactName . setTextContent ( creator . getUser ( ) . getName ( ) ) ;
dmpContactEmail . setTextContent ( creator . getUser ( ) . getEmail ( ) ) ;
}
}
dmpContactElement . appendChild ( dmpContactName ) ;
dmpContactElement . appendChild ( dmpContactEmail ) ;
dmpElement . appendChild ( dmpContactElement ) ;
Element dmpContributorsElement = xmlDoc . createElement ( "contributors" ) ;
Iterator < UserDMP > users = dmp . getUsers ( ) . iterator ( ) ;
while ( users . hasNext ( ) ) {
Element dmpContributorElement = xmlDoc . createElement ( "contributor" ) ;
Element dmpContributorName = xmlDoc . createElement ( "name" ) ;
Element dmpContributorEmail = xmlDoc . createElement ( "email" ) ;
UserDMP contributor = users . next ( ) ;
dmpContributorName . setTextContent ( contributor . getUser ( ) . getName ( ) ) ;
dmpContributorEmail . setTextContent ( contributor . getUser ( ) . getEmail ( ) ) ;
dmpContributorElement . appendChild ( dmpContributorName ) ;
dmpContributorElement . appendChild ( dmpContributorEmail ) ;
dmpContributorsElement . appendChild ( dmpContributorElement ) ;
}
dmpElement . appendChild ( dmpContributorsElement ) ;
// Funder.
Element funder = xmlDoc . createElement ( "funder" ) ;
Element funderLabel = xmlDoc . createElement ( "label" ) ;
@ -1464,6 +1498,13 @@ public class DataManagementPlanManager {
funderId . setTextContent ( dmp . getGrant ( ) . getFunder ( ) . getId ( ) . toString ( ) ) ;
funder . appendChild ( funderLabel ) ;
funder . appendChild ( funderId ) ;
if ( dmp . getGrant ( ) . getFunder ( ) . getReference ( ) ! = null ) {
String referencePrefix = dmp . getGrant ( ) . getFunder ( ) . getReference ( ) . split ( ":" ) [ 0 ] ;
String shortReference = dmp . getGrant ( ) . getFunder ( ) . getReference ( ) . substring ( referencePrefix . length ( ) + 1 ) ;
Element funderReference = xmlDoc . createElement ( "reference" ) ;
funderReference . setTextContent ( shortReference ) ;
funder . appendChild ( funderReference ) ;
}
dmpElement . appendChild ( funder ) ;
// Grant.
Element grant = xmlDoc . createElement ( "grant" ) ;
@ -1473,15 +1514,31 @@ public class DataManagementPlanManager {
grantId . setTextContent ( dmp . getGrant ( ) . getId ( ) . toString ( ) ) ;
grant . appendChild ( grantLabel ) ;
grant . appendChild ( grantId ) ;
if ( dmp . getGrant ( ) . getReference ( ) ! = null ) {
String referencePrefix = dmp . getGrant ( ) . getReference ( ) . split ( ":" ) [ 0 ] ;
String shortReference = dmp . getGrant ( ) . getReference ( ) . substring ( referencePrefix . length ( ) + 1 ) ;
Element grantReference = xmlDoc . createElement ( "reference" ) ;
grantReference . setTextContent ( shortReference ) ;
grant . appendChild ( grantReference ) ;
}
dmpElement . appendChild ( grant ) ;
// Project.
Element project = xmlDoc . createElement ( "project" ) ;
Element projectLabel = xmlDoc . createElement ( "label" ) ;
Element projectId = xmlDoc . createElement ( "id" ) ;
projectLabel . setTextContent ( dmp . getProject ( ) . getLabel ( ) ) ;
Element projectLabel = xmlDoc . createElement ( "label" ) ;
Element projectDescription = xmlDoc . createElement ( "description" ) ;
Element projectStartDate = xmlDoc . createElement ( "start" ) ;
Element projectEndDate = xmlDoc . createElement ( "end" ) ;
projectId . setTextContent ( dmp . getProject ( ) . getId ( ) . toString ( ) ) ;
project . appendChild ( projectLabel ) ;
projectLabel . setTextContent ( dmp . getProject ( ) . getLabel ( ) ) ;
projectDescription . setTextContent ( dmp . getProject ( ) . getDescription ( ) ) ;
projectStartDate . setTextContent ( dmp . getProject ( ) . getStartdate ( ) . toString ( ) ) ;
projectEndDate . setTextContent ( dmp . getProject ( ) . getEnddate ( ) . toString ( ) ) ;
project . appendChild ( projectId ) ;
project . appendChild ( projectLabel ) ;
project . appendChild ( projectDescription ) ;
project . appendChild ( projectStartDate ) ;
project . appendChild ( projectEndDate ) ;
dmpElement . appendChild ( project ) ;
Element organisationsElement = xmlDoc . createElement ( "organisations" ) ;
@ -1513,11 +1570,20 @@ public class DataManagementPlanManager {
for ( Dataset dataset : datasets ) {
Element datasetElement = xmlDoc . createElement ( "dataset" ) ;
Element datsetProfileElement = xmlDoc . createElement ( "profile" ) ;
datasetElement . setAttribute ( "name" , dataset . getLabel ( ) ) ;
Element datasetDescriptionElement = xmlDoc . createElement ( "description" ) ;
datasetElement . appendChild ( datasetDescriptionElement ) ;
datasetDescriptionElement . setTextContent ( dataset . getDescription ( ) ) ;
Element datsetProfileElement = xmlDoc . createElement ( "profile-id" ) ;
datasetElement . appendChild ( datsetProfileElement ) ;
datsetProfileElement . setTextContent ( dataset . getProfile ( ) . getId ( ) . toString ( ) ) ;
Element datsetProfileLabelElement = xmlDoc . createElement ( "profile-label" ) ;
datasetElement . appendChild ( datsetProfileLabelElement ) ;
datsetProfileLabelElement . setTextContent ( dataset . getProfile ( ) . getLabel ( ) ) ;
DatasetWizardModel datasetWizardModel = new DatasetWizardModel ( ) ;
Map < String , Object > properties = new HashMap < > ( ) ;
if ( dataset . getProperties ( ) ! = null ) {
@ -1535,12 +1601,18 @@ public class DataManagementPlanManager {
// Get DatasetProfiles from DMP to add to XML.
for ( DatasetProfile datasetProfile : dmp . getAssociatedDmps ( ) ) {
Element profile = xmlDoc . createElement ( "profile" ) ;
Element profileLabel = xmlDoc . createElement ( "profilelabel" ) ;
profileLabel . setTextContent ( datasetProfile . getLabel ( ) ) ;
profile . appendChild ( profileLabel ) ;
Element profileId = xmlDoc . createElement ( "profileId" ) ;
profileId . setTextContent ( datasetProfile . getId ( ) . toString ( ) ) ;
profile . appendChild ( profileId ) ;
Element profileGroupId = xmlDoc . createElement ( "profileGroupId" ) ;
profileGroupId . setTextContent ( datasetProfile . getGroupId ( ) . toString ( ) ) ;
profile . appendChild ( profileGroupId ) ;
Element profileLabel = xmlDoc . createElement ( "profileLabel" ) ;
profileLabel . setTextContent ( datasetProfile . getLabel ( ) ) ;
profile . appendChild ( profileLabel ) ;
Element profileVersion = xmlDoc . createElement ( "profileVersion" ) ;
profileVersion . setTextContent ( String . valueOf ( datasetProfile . getVersion ( ) ) ) ;
profile . appendChild ( profileVersion ) ;
profiles . appendChild ( profile ) ;
}
dmpElement . appendChild ( profiles ) ;
@ -1556,13 +1628,12 @@ public class DataManagementPlanManager {
return fileEnvelope ;
}
public ResponseEntity< byte [ ] > getRDAJsonDocument ( String id , Principal principal ) throws Exception {
public FileEnvelope getRDAJsonDocument ( String id , Principal principal ) throws Exception {
eu . eudat . data . entities . DMP dmp = databaseRepository . getDmpDao ( ) . find ( UUID . fromString ( id ) ) ;
if ( ! dmp . isPublic ( ) & & dmp . getUsers ( ) . stream ( ) . noneMatch ( userInfo - > userInfo . getUser ( ) . getId ( ) = = principal . getId ( ) ) )
throw new UnauthorisedException ( ) ;
// RDAExportModel rdaExportModel = new RDAExportModel().fromDataModel(dmp, datasetManager, principal);
final Boolean isFinalized = dmp . getStatus ( ) = = DMP . DMPStatus . FINALISED . getValue ( ) ;
final Boolean isPublic = dmp . isPublic ( ) ;
final boolean isFinalized = dmp . getStatus ( ) = = DMP . DMPStatus . FINALISED . getValue ( ) ;
final boolean isPublic = dmp . isPublic ( ) ;
dmp . setDataset ( dmp . getDataset ( ) . stream ( )
. filter ( dataset - > dataset . getStatus ( ) ! = Dataset . Status . DELETED . getValue ( ) & &
dataset . getStatus ( ) ! = Dataset . Status . CANCELED . getValue ( ) )
@ -1570,15 +1641,12 @@ public class DataManagementPlanManager {
. collect ( Collectors . toSet ( ) ) ) ;
String result = rdaManager . convertToRDA ( dmp ) ;
/ * ObjectMapper mapper = new ObjectMapper ( ) ;
mapper . setSerializationInclusion ( JsonInclude . Include . NON_NULL ) ; * /
String fileName = "DMP_" + dmp . getGrant ( ) . getLabel ( ) + "_" + dmp . getVersion ( ) ; //dmp.getLabel();
String fileName = "DMP_" + dmp . getGrant ( ) . getLabel ( ) + "_" + dmp . getVersion ( ) ;
fileName = fileName . replaceAll ( "[^a-zA-Z0-9+ ]" , "" ) . replace ( " " , "_" ) . replace ( "," , "_" ) ;
String uuid = UUID . randomUUID ( ) . toString ( ) ;
File file = new File ( this . environment . getProperty ( "temp.temp" ) + uuid + ".json" ) ;
OutputStream output = new FileOutputStream ( file ) ;
try {
// mapper.writeValue(file, rdaExportModel);
output . write ( result . getBytes ( ) ) ;
output . flush ( ) ;
output . close ( ) ;
@ -1586,18 +1654,10 @@ public class DataManagementPlanManager {
logger . error ( e . getMessage ( ) , e ) ;
}
InputStream resource = new FileInputStream ( file ) ;
HttpHeaders responseHeaders = new HttpHeaders ( ) ;
responseHeaders . setContentLength ( file . length ( ) ) ;
responseHeaders . setContentType ( MediaType . APPLICATION_OCTET_STREAM ) ;
responseHeaders . set ( "Content-Disposition" , "attachment;filename=" + fileName + ".json" ) ;
responseHeaders . set ( "Access-Control-Expose-Headers" , "Content-Disposition" ) ;
responseHeaders . get ( "Access-Control-Expose-Headers" ) . add ( "Content-Type" ) ;
byte [ ] content = org . apache . poi . util . IOUtils . toByteArray ( resource ) ;
resource . close ( ) ;
Files . deleteIfExists ( file . toPath ( ) ) ;
return new ResponseEntity < > ( content , responseHeaders , HttpStatus . OK ) ;
FileEnvelope rdaJsonDocument = new FileEnvelope ( ) ;
rdaJsonDocument . setFilename ( fileName + ".json" ) ;
rdaJsonDocument . setFile ( file ) ;
return rdaJsonDocument ;
}
public ResponseEntity < byte [ ] > getDocument ( String id , String contentType , Principal principal , ConfigLoader configLoader ) throws InstantiationException , IllegalAccessException , IOException {
@ -2041,100 +2101,6 @@ public class DataManagementPlanManager {
return null ;
}
private String getUnpublishedDOI ( String DOI , String token , Integer version ) {
try {
RestTemplate restTemplate = new RestTemplate ( ) ;
HttpHeaders headers = new HttpHeaders ( ) ;
headers . setAccept ( Collections . singletonList ( MediaType . APPLICATION_JSON ) ) ;
headers . setContentType ( MediaType . APPLICATION_JSON ) ;
Map createResponse = null ;
LinkedHashMap < String , String > links = null ;
LinkedHashMap < String , String > metadata = null ;
String listUrl = this . environment . getProperty ( "zenodo.url" ) + "deposit/depositions" + "?q=conceptdoi:\"" + DOI + "\"&access_token=" + token ;
ResponseEntity < Map [ ] > listResponses = restTemplate . getForEntity ( listUrl , Map [ ] . class ) ;
createResponse = listResponses . getBody ( ) [ 0 ] ;
metadata = ( LinkedHashMap < String , String > ) createResponse . get ( "metadata" ) ;
links = ( LinkedHashMap < String , String > ) createResponse . get ( "links" ) ;
if ( metadata . get ( "version" ) . equals ( version . toString ( ) ) ) {
return links . get ( "publish" ) ;
} else {
return null ;
}
} catch ( Exception e ) {
logger . warn ( e . getMessage ( ) , e ) ;
return null ;
}
}
public String createZenodoDoi ( UUID id , Principal principal ) throws Exception {
return this . createZenodoDoi ( id , principal , false ) ;
}
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" ) ;
if ( ! dmp . getStatus ( ) . equals ( DMP . DMPStatus . FINALISED . getValue ( ) ) )
throw new Exception ( "DMP is not finalized" ) ;
/ * if ( dmp . getDoi ( ) ! = null )
throw new Exception ( "DMP already has a DOI" ) ; * /
FileEnvelope file = getWordDocument ( id . toString ( ) , principal , configLoader ) ;
String name = file . getFilename ( ) . substring ( 0 , file . getFilename ( ) . length ( ) - 5 ) ;
File pdfFile = PDFUtils . convertToPDF ( file , environment ) ;
String fileName = name + ".pdf" ;
ResponseEntity < byte [ ] > jsonFile ;
try {
jsonFile = getRDAJsonDocument ( id . toString ( ) , principal ) ;
} catch ( Exception e ) {
throw e ;
}
String previousDOI = this . getPreviousDOI ( dmp . getGroupId ( ) , dmp . getId ( ) , "Zenodo" ) ;
File supportingFilesZip = this . createSupportingFilesZip ( dmp ) ;
DMPDepositModel dmpDepositModel = DMPToDepositMapper . fromDMP ( dmp , pdfFile , fileName , jsonFile , supportingFilesZip , previousDOI ) ;
String zenodoToken = "" ;
try {
if ( this . userManager . isDOITokenValid ( principal ) ) {
zenodoToken = principal . getZenodoToken ( ) ;
}
} catch ( NonValidTokenException e ) {
zenodoToken = this . environment . getProperty ( "zenodo.access_token" ) ;
}
String finalDoi = null ;
for ( RepositoryDeposit repo : this . repositoriesDeposit ) { //temp
if ( repo . getConfiguration ( ) . getRepositoryId ( ) . equals ( "Zenodo" ) ) {
finalDoi = repo . deposit ( dmpDepositModel , zenodoToken ) ;
if ( finalDoi ! = null ) {
EntityDoi doiEntity = new EntityDoi ( ) ;
doiEntity . setId ( UUID . randomUUID ( ) ) ;
doiEntity . setEntityType ( EntityDoi . EntityType . DMP ) ;
doiEntity . setDoi ( finalDoi ) ;
doiEntity . setRepositoryId ( "Zenodo" ) ;
Date now = new Date ( ) ;
doiEntity . setCreatedAt ( now ) ;
doiEntity . setUpdatedAt ( now ) ;
doiEntity . setEntityId ( dmp ) ;
apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getEntityDoiDao ( ) . createOrUpdate ( doiEntity ) ;
dmp . getDois ( ) . add ( doiEntity ) ;
apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getDmpDao ( ) . createOrUpdate ( dmp ) ;
}
}
}
if ( supportingFilesZip ! = null ) {
Files . deleteIfExists ( supportingFilesZip . toPath ( ) ) ;
}
Files . deleteIfExists ( pdfFile . toPath ( ) ) ;
Files . deleteIfExists ( file . getFile ( ) . toPath ( ) ) ;
return finalDoi ;
}
public Doi createDoi ( DepositRequest depositRequest , Principal principal ) throws Exception {
DMP dmp = this . apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getDmpDao ( ) . find ( UUID . fromString ( depositRequest . getDmpId ( ) ) ) ;
if ( ! isUserOwnerOfDmp ( dmp , principal ) )
@ -2147,18 +2113,22 @@ public class DataManagementPlanManager {
FileEnvelope file = getWordDocument ( depositRequest . getDmpId ( ) , principal , configLoader ) ;
String name = file . getFilename ( ) . substring ( 0 , file . getFilename ( ) . length ( ) - 5 ) . replaceAll ( "[^a-zA-Z0-9_+ ]" , "" ) . replace ( " " , "_" ) . replace ( "," , "_" ) ;
File pdfFile = PDFUtils . convertToPDF ( file , environment ) ;
String fileName = name + ".pdf" ;
ResponseEntity < byte [ ] > jsonFile ;
eu . eudat . depositinterface . models . FileEnvelope pdfEnvelope = new eu . eudat . depositinterface . models . FileEnvelope ( ) ;
pdfEnvelope . setFile ( pdfFile ) ;
pdfEnvelope . setFilename ( name + ".pdf" ) ;
eu . eudat . depositinterface . models . FileEnvelope rdaJsonFile = new eu . eudat . depositinterface . models . FileEnvelope ( ) ;
try {
jsonFile = getRDAJsonDocument ( depositRequest . getDmpId ( ) , principal ) ;
FileEnvelope rdaJsonDocument = getRDAJsonDocument ( depositRequest . getDmpId ( ) , principal ) ;
rdaJsonFile . setFile ( rdaJsonDocument . getFile ( ) ) ;
rdaJsonFile . setFilename ( rdaJsonDocument . getFilename ( ) ) ;
} catch ( Exception e ) {
throw e ;
logger . error ( e . getMessage ( ) , e ) ;
}
String previousDOI = this . getPreviousDOI ( dmp . getGroupId ( ) , dmp . getId ( ) , depositRequest . getRepositoryId ( ) ) ;
File supportingFilesZip = this . createSupportingFilesZip ( dmp ) ;
DMPDepositModel dmpDepositModel = DMPToDepositMapper . fromDMP ( dmp , pdf File, fileName , j sonFile, supportingFilesZip , previousDOI ) ;
DMPDepositModel dmpDepositModel = DMPToDepositMapper . fromDMP ( dmp , pdf Envelope, rdaJ sonFile, supportingFilesZip , previousDOI ) ;
Optional < RepositoryDeposit > repo = this . repositoriesDeposit . stream ( ) . filter ( x - > x . getConfiguration ( ) . getRepositoryId ( ) . equals ( depositRequest . getRepositoryId ( ) ) ) . findFirst ( ) ;
String finalDoi = repo . map ( r - > {
@ -2192,10 +2162,12 @@ public class DataManagementPlanManager {
if ( supportingFilesZip ! = null ) {
Files . deleteIfExists ( supportingFilesZip . toPath ( ) ) ;
}
Files . deleteIfExists ( rdaJsonFile . getFile ( ) . toPath ( ) ) ;
Files . deleteIfExists ( pdfFile . toPath ( ) ) ;
Files . deleteIfExists ( file . getFile ( ) . toPath ( ) ) ;
return doiModel ;
}
private File createSupportingFilesZip ( DMP dmp ) throws IOException {