some fixes
This commit is contained in:
parent
7716f199ad
commit
96ec14722c
|
@ -22,9 +22,10 @@ public interface OrganizationRepository extends JpaRepository<Organization, Stri
|
|||
@Query("update Organization set status = ?2 where id = ?1")
|
||||
void updateStatus(String id, String status);
|
||||
|
||||
// to override the generation strategy of the ID
|
||||
@Modifying
|
||||
@Query(value = "insert into organizations(id) values (?1)", nativeQuery = true)
|
||||
void preparePendingOrg(String id);
|
||||
void prepareOrgWithId(String id);
|
||||
|
||||
double countByStatus(String string);
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@ public class DatabaseUtils {
|
|||
final String pendingId = OpenOrgsConstants.OPENORGS_PENDING_PREFIX + UUID.randomUUID();
|
||||
orgView.setId(pendingId);
|
||||
// to override the generation strategy of the ID
|
||||
organizationRepository.preparePendingOrg(pendingId);
|
||||
organizationRepository.prepareOrgWithId(pendingId);
|
||||
} else {
|
||||
orgView.setId(null); // The ID is generated by the DB
|
||||
}
|
||||
|
@ -483,32 +483,35 @@ public class DatabaseUtils {
|
|||
|
||||
final List<OrganizationView> persistents = views.stream().filter(v -> v.getPersistent()).collect(Collectors.toList());
|
||||
|
||||
final OrganizationView masterOrg = new OrganizationView();
|
||||
|
||||
if (persistents.size() > 1) {
|
||||
throw new RuntimeException("Too many persintent organizations");
|
||||
} else if (persistents.size() == 1) {
|
||||
backupOrg(persistents.get(0), user);
|
||||
return fixConflicts(persistents.get(0), views, user);
|
||||
masterOrg.setId(persistents.get(0).getId());
|
||||
masterOrg.setStatus(OrganizationStatus.approved.toString());
|
||||
} else {
|
||||
// I create a new org
|
||||
final OrganizationView masterOrg = new OrganizationView();
|
||||
masterOrg.setId(null);
|
||||
masterOrg.setStatus(null);
|
||||
return fixConflicts(masterOrg, views, user);
|
||||
}
|
||||
return fixConflicts(masterOrg, views, user);
|
||||
}
|
||||
|
||||
private String backupOrg(final OrganizationView org, final String user) {
|
||||
final String origId = org.getId();
|
||||
final String backupId = origId + "::" + OffsetDateTime.now().toEpochSecond();
|
||||
|
||||
organizationRepository.prepareOrgWithId(backupId);
|
||||
try {
|
||||
|
||||
final OrganizationView backupOrg = (OrganizationView) BeanUtils.cloneBean(org);
|
||||
backupOrg.setId(backupId);
|
||||
backupOrg.setStatus(OrganizationStatus.hidden.toString());
|
||||
|
||||
insertOrUpdateOrganization(backupOrg, user, false);
|
||||
|
||||
organizationRepository.updateStatus(backupId, OrganizationStatus.hidden.toString());
|
||||
|
||||
journalEntryRepository
|
||||
.save(new JournalEntry(origId, JournalOperations.BACKUP_ORG, "Saved a backup copy: " + backupId, user));
|
||||
journalEntryRepository
|
||||
|
@ -560,7 +563,7 @@ public class DatabaseUtils {
|
|||
.forEach(id -> {
|
||||
hideConflictOrgs(masterId, id);
|
||||
journalEntryRepository
|
||||
.save(new JournalEntry(masterId, JournalOperations.FIX_CONFLICT, "The org has been hidded and merged in " + masterId, user));
|
||||
.save(new JournalEntry(id, JournalOperations.FIX_CONFLICT, "The org has been hidded and merged in " + masterId, user));
|
||||
});
|
||||
|
||||
// I reassign the duplicates to the new org
|
||||
|
|
Loading…
Reference in New Issue