-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3176 from dzhw/cschwartze/issue3129
#3129 initial version of sponsor modification regarding funding ref
- Loading branch information
Showing
30 changed files
with
438 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...management/analysispackagemanagement/repository/changelogs/RecreateSponsorsChangeLog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package eu.dzhw.fdz.metadatamanagement.analysispackagemanagement.repository.changelogs; | ||
|
||
import org.bson.Document; | ||
|
||
import com.github.cloudyrock.mongock.ChangeLog; | ||
import com.github.cloudyrock.mongock.ChangeSet; | ||
import com.mongodb.client.MongoCollection; | ||
import com.mongodb.client.MongoDatabase; | ||
import com.mongodb.client.model.Filters; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Recreating sponsor data after model modification (e.g. fundingRef). | ||
* | ||
* @author cschwartze | ||
*/ | ||
@Slf4j | ||
@ChangeLog | ||
public class RecreateSponsorsChangeLog { | ||
|
||
/** | ||
* Recreating sponsor data after model modification. | ||
* | ||
* @param db Mongo db client. | ||
*/ | ||
@ChangeSet(order = "1", id = "recreateAnalysisPackageSponsors", author = "cschwartze", runAlways = true) | ||
public void recreateSponsors(MongoDatabase db) { | ||
MongoCollection<Document> analysisPackages = db.getCollection("analysis_packages"); | ||
List results = new ArrayList<>(); | ||
analysisPackages.find().into(results); | ||
results.forEach(analysisPckg -> { | ||
Object id = ((Document) analysisPckg).get("dataAcquisitionProjectId"); | ||
List<Document> sponsors = ((Document) analysisPckg).getList("sponsors", Document.class); | ||
if (sponsors != null) { | ||
if (sponsors.get(0).keySet().contains("de")) { | ||
log.info("Recreate sponsors for " + id); | ||
List newSponsors = new ArrayList<>(); | ||
sponsors.forEach(s -> { | ||
Document newSponsor = Document.parse("{\"name\" : " + s.toJson() + ", \"fundingRef\" : null}"); | ||
newSponsors.add(newSponsor); | ||
}); | ||
((Document) analysisPckg).append("sponsors", newSponsors); | ||
if (analysisPackages.findOneAndReplace( | ||
Filters.eq("dataAcquisitionProjectId", id), (Document) analysisPckg) != null) { | ||
log.info("Sponsors for analysis package " + id + " recreated."); | ||
} else { | ||
log.warn("Sponsors for analysis package " + id + " could not recreated."); | ||
} | ||
} | ||
if (sponsors.get(0).keySet().contains("name")) { | ||
log.info("Sponsor data appears to have already been migrated for analysis package " + id + "."); | ||
} | ||
} | ||
}); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/eu/dzhw/fdz/metadatamanagement/common/domain/Sponsor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package eu.dzhw.fdz.metadatamanagement.common.domain; | ||
|
||
import java.io.Serializable; | ||
|
||
import org.javers.core.metamodel.annotation.ValueObject; | ||
|
||
import eu.dzhw.fdz.metadatamanagement.common.domain.validation.I18nStringSize; | ||
import eu.dzhw.fdz.metadatamanagement.common.domain.validation.StringLengths; | ||
import eu.dzhw.fdz.metadatamanagement.common.domain.validation.I18nStringEntireNotEmpty; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* A representation of a sponsor. | ||
*/ | ||
@NoArgsConstructor | ||
@Data | ||
@AllArgsConstructor | ||
@Builder | ||
@ValueObject | ||
public class Sponsor implements Serializable { | ||
|
||
private static final long serialVersionUID = -2205399590286037466L; | ||
|
||
/** | ||
* The name of the sponsor which has sponsored the study or project from which this data | ||
* package results. | ||
* | ||
* It must be specified in German and English and it must not contain more than 512 characters. | ||
*/ | ||
@I18nStringSize(max = StringLengths.MEDIUM, | ||
message = "data-package-management.error.data-package.sponsor.i18n-string-size") | ||
@I18nStringEntireNotEmpty( | ||
message = "data-package-management.error.data-package.sponsor.i18n-string-size") | ||
private I18nString name; | ||
|
||
/** | ||
* The funding reference number. | ||
* | ||
* May be a number or a combination of numbers, letters and/or special characters. | ||
*/ | ||
private String fundingRef; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...datamanagement/datapackagemanagement/repository/changelogs/RecreateSponsorsChangeLog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package eu.dzhw.fdz.metadatamanagement.datapackagemanagement.repository.changelogs; | ||
|
||
import org.bson.Document; | ||
|
||
import com.github.cloudyrock.mongock.ChangeLog; | ||
import com.github.cloudyrock.mongock.ChangeSet; | ||
import com.mongodb.client.MongoCollection; | ||
import com.mongodb.client.MongoDatabase; | ||
import com.mongodb.client.model.Filters; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Recreating sponsor data after model modification (e.g. fundingRef). | ||
* | ||
* @author cschwartze | ||
*/ | ||
@Slf4j | ||
@ChangeLog | ||
public class RecreateSponsorsChangeLog { | ||
|
||
/** | ||
* Recreating sponsor data after model modification. | ||
* | ||
* @param db Mongo db client. | ||
*/ | ||
@ChangeSet(order = "1", id = "recreateDataPackageSponsors", author = "cschwartze", runAlways = true) | ||
public void recreateSponsors(MongoDatabase db) { | ||
MongoCollection<Document> dataPackages = db.getCollection("data_packages"); | ||
List results = new ArrayList<>(); | ||
dataPackages.find().into(results); | ||
results.forEach(dataPckg -> { | ||
Object id = ((Document) dataPckg).get("dataAcquisitionProjectId"); | ||
List<Document> sponsors = ((Document) dataPckg).getList("sponsors", Document.class); | ||
if (sponsors != null) { | ||
if (sponsors.get(0).keySet().contains("de")) { | ||
log.info("Recreate sponsors for " + id); | ||
List newSponsors = new ArrayList<>(); | ||
sponsors.forEach(s -> { | ||
Document newSponsor = Document.parse("{\"name\" : " + s.toJson() + ", \"fundingRef\" : null}"); | ||
newSponsors.add(newSponsor); | ||
}); | ||
((Document) dataPckg).append("sponsors", newSponsors); | ||
if (dataPackages.findOneAndReplace( | ||
Filters.eq("dataAcquisitionProjectId", id), (Document) dataPckg) != null) { | ||
log.info("Sponsors for data package " + id + " recreated."); | ||
} else { | ||
log.warn("Sponsors for data package " + id + " could not recreated."); | ||
} | ||
} | ||
if (sponsors.get(0).keySet().contains("name")) { | ||
log.info("Sponsor data appears to have already been migrated for data package " + id + "."); | ||
} | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.