Commit 63848b3c authored by Matija Obreza's avatar Matija Obreza
Browse files

Update FaoInstitute countries based on WIEWS code

parent feade8a3
......@@ -14,13 +14,20 @@
* limitations under the License.
**/
package org.genesys2.server.persistence.domain;
import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.FaoInstitute;
public interface GenesysLowlevelRepository {
void updateCountryRefs();
void updateFaoInstituteRefs();
/**
* Relink {@link FaoInstitute} with {@link Country} based on institute code
*/
void updateFaoInstituteCountries();
}
......@@ -22,6 +22,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
......@@ -38,6 +39,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
public void updateFaoInstituteRefs() {
LOG.info("Updating institute references");
......@@ -52,10 +54,21 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
public void updateCountryRefs() {
LOG.info("Updating country references");
int count = jdbcTemplate.update("UPDATE `accession` A inner join `country` C on C.code3=A.Origin set A.originId=C.id WHERE A.Origin IS NOT NULL;");
LOG.info("Country references updated: " + count);
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
public void updateFaoInstituteCountries() {
LOG.info("Updating country references");
int count = jdbcTemplate.update("UPDATE `faoinstitute` I inner join `country` C on C.code3=left(I.code, 3) set I.countryId=C.id;");
LOG.info("Country references updated: " + count);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment