Commit 42c9a0be authored by Matija Obreza's avatar Matija Obreza
Browse files

Don't automatically create the ISO639-3 vocabulary

parent 15cd05ff
......@@ -55,27 +55,29 @@ public class PartnerServiceImpl implements PartnerService, InitializingBean {
@Value("${partner.primary.uuid}")
private UUID primaryPartnerUuid;
private Partner primaryPartner;
@Override
@Transactional
public void afterPropertiesSet() throws Exception {
Partner primaryPartner = loadPartner(primaryPartnerUuid);
getPrimaryPartner();
}
@Override
@Transactional
public Partner getPrimaryPartner() {
Partner primaryPartner = partnerRepository.findByUuid(primaryPartnerUuid);
if (primaryPartner == null) {
primaryPartner=new Partner();
// We recreate it if necessary
primaryPartner = new Partner();
primaryPartner.setUuid(primaryPartnerUuid);
primaryPartner.setName("Genesys Catalog");
primaryPartner.setShortName("genesys");
primaryPartner = createPartner(primaryPartner);
}
this.primaryPartner = primaryPartner;
}
@Override
public Partner getPrimaryPartner() {
return primaryPartner;
}
/**
* {@inheritDoc}
*/
......@@ -169,7 +171,7 @@ public class PartnerServiceImpl implements PartnerService, InitializingBean {
public Partner loadPartner(UUID uuid, int version) {
return lazyLoad(partnerRepository.findByUuidAndVersion(uuid, version));
}
/**
* {@inheritDoc}
*/
......
......@@ -34,6 +34,7 @@ import org.genesys.catalog.service.worker.GeonamesISOLanguageSource.LanguageInfo
import org.genesys.catalog.service.worker.ISO3166VocabularyUpdater;
import org.genesys.catalog.service.worker.ISO639VocabularyUpdater;
import org.genesys.catalog.test.ServiceTest;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -43,6 +44,7 @@ import org.springframework.beans.factory.annotation.Autowired;
* @author Matija Obreza
* @author Maxym Borodenko
*/
@Ignore
public class AutomaticVocabulariesTest extends ServiceTest {
@Autowired
......
......@@ -29,7 +29,6 @@ import org.genesys.catalog.service.VocabularyService;
import org.genesys.catalog.service.worker.ISO639VocabularyUpdater;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -48,7 +47,7 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(LanguagesController.API_BASE)
@PreAuthorize("isAuthenticated()")
public class LanguagesController implements InitializingBean {
public class LanguagesController {
protected static final String API_BASE = "/api/v0/lang";
public static final UUID ISO639_3 = ISO639VocabularyUpdater.ISO639_3;
......@@ -64,29 +63,23 @@ public class LanguagesController implements InitializingBean {
@Autowired
private PartnerService partnerService;
@Override
public void afterPropertiesSet() throws Exception {
final ControlledVocabulary iso639 = vocabularyService.getVocabulary(ISO639_3);
if (iso639 == null) {
ControlledVocabulary updated = iso639VocabularyUpdater.getISO639Vocabulary();
updated.setUuid(ISO639_3);
updated.setOwner(partnerService.getPrimaryPartner());
updated = vocabularyService.createVocabulary(updated);
LOG.info("Created ISO639-3 vocabulary with {} terms", updated.getTerms().size());
}
}
@PreAuthorize("hasRole('ADMINISTRATOR')")
@PostMapping(value = "/update")
public ControlledVocabulary updateLanguages() throws IOException {
final ControlledVocabulary iso639 = vocabularyService.getVocabulary(ISO639_3);
ControlledVocabulary updated = iso639VocabularyUpdater.getISO639Vocabulary();
updated.setUuid(iso639.getUuid());
updated.setVersion(iso639.getVersion());
LOG.info("Updating ISO639-3 vocabulary with {} terms", updated.getTerms().size());
return vocabularyService.updateVocabulary(updated);
if (iso639 != null) {
updated.setUuid(iso639.getUuid());
updated.setVersion(iso639.getVersion());
LOG.info("Updating ISO639-3 vocabulary with {} terms", updated.getTerms().size());
return vocabularyService.updateVocabulary(updated);
} else {
updated.setUuid(ISO639_3);
updated.setOwner(partnerService.getPrimaryPartner());
LOG.info("Creating ISO639-3 vocabulary with {} terms", updated.getTerms().size());
return vocabularyService.createVocabulary(updated);
}
}
@GetMapping(value = "/{code}", produces = MediaType.APPLICATION_JSON_VALUE)
......
......@@ -23,7 +23,12 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.genesys.catalog.model.vocab.ControlledVocabulary;
import org.genesys.catalog.model.vocab.VocabularyTerm;
import org.genesys.catalog.server.controller.rest.AbstractRestTest;
import org.genesys.catalog.service.PartnerService;
import org.genesys.catalog.service.VocabularyService;
import org.genesys.catalog.service.worker.ISO639VocabularyUpdater;
import org.genesys.catalog.service.worker.GeonamesISOLanguageSource.LanguageInfo;
import org.junit.Before;
import org.junit.Test;
......@@ -36,6 +41,8 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.WebApplicationContext;
import com.google.common.collect.Lists;
/**
* The Class LanguagesControllerTest.
*
......@@ -47,12 +54,28 @@ public class LanguagesControllerTest extends AbstractRestTest {
private WebApplicationContext webApplicationContext;
private MockMvc mockMvc;
@Autowired
private VocabularyService vocabularyService;
@Autowired
private PartnerService partnerService;
@Before
@Transactional
public void setUp() throws Exception {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(documentationConfiguration(restDocumentation).uris().withScheme("https").withHost(
"api.catalog.genesys-pgr.org").withPort(443)).build();
if (vocabularyService.getVocabulary(ISO639VocabularyUpdater.ISO639_3) == null) {
// create the vocabulary
ControlledVocabulary vocabulary=new ControlledVocabulary();
vocabulary.setUuid(ISO639VocabularyUpdater.ISO639_3);
vocabulary.setOwner(partnerService.getPrimaryPartner());
vocabulary.setTitle("ISO649-3");
vocabulary.setTerms(Lists.newArrayList(VocabularyTerm.fromData("eng", "English"), VocabularyTerm.fromData("ukr", "Ukrainian")));
vocabularyService.createVocabulary(vocabulary);
}
}
@Test
......
Supports Markdown
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