Commit 8635e088 authored by Matija Obreza's avatar Matija Obreza
Browse files

Update accession-country references, accession-faoinstitute references

parent 4c25b575
/**
* Copyright 2013 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.crophub.rest.common.persistence.domain;
public interface GenesysLowlevelRepository {
void updateCountryRefs();
void updateFaoInstituteRefs();
}
/**
* Copyright 2013 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.crophub.rest.common.persistence.domain;
import javax.sql.DataSource;
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.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
@Repository
@Transactional(readOnly = true)
public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository {
public static final Log LOG = LogFactory.getLog(GenesysLowlevelRepositoryImpl.class);
private JdbcTemplate jdbcTemplate;
@Autowired
public void setDataSource(final DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@Override
@Transactional(readOnly = false)
public void updateFaoInstituteRefs() {
LOG.info("Updating institute references");
int count = jdbcTemplate.update("UPDATE `accession` A inner join `faoinstitute` FI on FI.code=A.Institute set A.instituteId=FI.id;");
LOG.info("Institute references updated: " + count);
LOG.info("Updating institute accession count");
count = jdbcTemplate
.update("UPDATE faoinstitute FI inner join (select instituteId, count(*) X from accession group by instituteId) A on A.instituteId=FI.id set FI.accessionCount=A.X;");
LOG.info("Institute accession counts updated: " + count);
}
@Override
@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);
}
}
......@@ -96,4 +96,8 @@ public interface GenesysService {
Page<Accession> listAccessionsByOrganization(Organization organization, Pageable pageable);
void updateAccessionCountryRefs();
void updateAccessionInstitueRefs();
}
......@@ -45,6 +45,7 @@ import org.crophub.rest.common.persistence.domain.AccessionNameRepository;
import org.crophub.rest.common.persistence.domain.AccessionRepository;
import org.crophub.rest.common.persistence.domain.AccessionTraitRepository;
import org.crophub.rest.common.persistence.domain.CropTaxonomyRepository;
import org.crophub.rest.common.persistence.domain.GenesysLowlevelRepository;
import org.crophub.rest.common.persistence.domain.MetadataMethodRepository;
import org.crophub.rest.common.persistence.domain.MetadataRepository;
import org.crophub.rest.common.persistence.domain.MethodRepository;
......@@ -100,6 +101,9 @@ public class GenesysServiceImpl implements GenesysService, TraitService {
@Autowired
private OrganizationRepository organizationRepository;
@Autowired
private GenesysLowlevelRepository genesysLowlevelRepository;
@Override
public long countByInstitute(FaoInstitute institute) {
return accessionRepository.countByInstitute(institute);
......@@ -275,4 +279,16 @@ public class GenesysServiceImpl implements GenesysService, TraitService {
public List<Metadata> listMetadataByMethod(Method method) {
return metadataMethodRepository.listMetadataByMethod(method);
}
@Override
@Transactional(readOnly = false)
public void updateAccessionCountryRefs() {
genesysLowlevelRepository.updateCountryRefs();
}
@Override
@Transactional(readOnly = false)
public void updateAccessionInstitueRefs() {
genesysLowlevelRepository.updateFaoInstituteRefs();
}
}
......@@ -20,6 +20,7 @@ import java.io.IOException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.crophub.rest.common.service.GenesysService;
import org.crophub.rest.common.service.GeoService;
import org.crophub.rest.common.service.LuceneIndexer;
import org.crophub.rest.common.service.impl.InstituteUpdater;
......@@ -40,6 +41,9 @@ public class AdminController {
@Autowired
LuceneIndexer luceneIndexer;
@Autowired
GenesysService genesysService;
@Autowired
GeoService geoService;
......@@ -73,11 +77,22 @@ public class AdminController {
luceneIndexer.reindexEverything();
return "redirect:/admin/";
}
@RequestMapping(method = RequestMethod.POST, value = "/reindexEntity")
public String reindexEntities(@RequestParam("entity") String entityName) {
luceneIndexer.reindexEntity(entityName);
return "redirect:/admin/";
}
@RequestMapping(method = RequestMethod.POST, value = "/updateAccessionCountryRefs")
public String updateAccessionCountryRefs() {
genesysService.updateAccessionCountryRefs();
return "redirect:/admin/";
}
@RequestMapping(method = RequestMethod.POST, value = "/updateAccessionInstituteRefs")
public String updateAccessionInstituteRefs() {
genesysService.updateAccessionInstitueRefs();
return "redirect:/admin/";
}
}
......@@ -22,6 +22,13 @@
<form method="post" action="<c:url value="/admin/reindexEverything" />">
<input type="submit" value="Reindex search indexes" />
</form>
<form method="post" action="<c:url value="/admin/updateAccessionCountryRefs" />">
<input type="submit" value="Update accession country info" />
</form>
<form method="post" action="<c:url value="/admin/updateAccessionInstituteRefs" />">
<input type="submit" value="Update accession institute info" />
</form>
<form method="post" action="<c:url value="/admin/reindexEntity" />">
......
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