Commit a30edfb3 authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch 'minor-updates' into 'main'

Fix: Never generate barcodes for system inventories

See merge request grin-global/grin-global-server!402
parents ba0c9556 ee012aab
...@@ -433,6 +433,10 @@ public class InventoryServiceImpl extends FilteredCRUDServiceImpl<Inventory, Inv ...@@ -433,6 +433,10 @@ public class InventoryServiceImpl extends FilteredCRUDServiceImpl<Inventory, Inv
public String assignBarcode(Inventory inventory) { public String assignBarcode(Inventory inventory) {
inventory = get(inventory); inventory = get(inventory);
if (inventory.isSystemInventory()) {
throw new InvalidApiUsageException("System inventories do not have barcodes");
}
if (StringUtils.isNotBlank(inventory.getBarcode())) if (StringUtils.isNotBlank(inventory.getBarcode()))
return inventory.getBarcode(); // return existing barcode return inventory.getBarcode(); // return existing barcode
......
...@@ -308,7 +308,7 @@ public class TaxonomyControllerTest extends AbstractApiV1Test { ...@@ -308,7 +308,7 @@ public class TaxonomyControllerTest extends AbstractApiV1Test {
.perform(post(TaxonomyController.SpeciesController.API_URL + "/filter?d=ASC&s=nameVerifiedDate") .perform(post(TaxonomyController.SpeciesController.API_URL + "/filter?d=ASC&s=nameVerifiedDate")
.content(verboseMapper.writeValueAsString(filter)) .content(verboseMapper.writeValueAsString(filter))
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
.andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print()) // .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$", not(nullValue()))) .andExpect(jsonPath("$", not(nullValue())))
......
...@@ -59,6 +59,7 @@ import org.gringlobal.persistence.AccessionPedigreeRepository; ...@@ -59,6 +59,7 @@ import org.gringlobal.persistence.AccessionPedigreeRepository;
import org.gringlobal.persistence.AccessionQuarantineRepository; import org.gringlobal.persistence.AccessionQuarantineRepository;
import org.gringlobal.persistence.AccessionRepository; import org.gringlobal.persistence.AccessionRepository;
import org.gringlobal.persistence.AccessionSourceRepository; import org.gringlobal.persistence.AccessionSourceRepository;
import org.gringlobal.persistence.AppSettingRepository;
import org.gringlobal.persistence.CitationRepository; import org.gringlobal.persistence.CitationRepository;
import org.gringlobal.persistence.CooperatorRepository; import org.gringlobal.persistence.CooperatorRepository;
import org.gringlobal.persistence.GeographyRepository; import org.gringlobal.persistence.GeographyRepository;
...@@ -74,6 +75,7 @@ import org.gringlobal.persistence.SysLangRepository; ...@@ -74,6 +75,7 @@ import org.gringlobal.persistence.SysLangRepository;
import org.gringlobal.persistence.TaxonomyFamilyRepository; import org.gringlobal.persistence.TaxonomyFamilyRepository;
import org.gringlobal.persistence.TaxonomyGenusRepository; import org.gringlobal.persistence.TaxonomyGenusRepository;
import org.gringlobal.persistence.TaxonomySpeciesRepository; import org.gringlobal.persistence.TaxonomySpeciesRepository;
import org.gringlobal.service.AppSettingsService;
import org.gringlobal.service.InventoryService; import org.gringlobal.service.InventoryService;
import org.gringlobal.test.base.AbstractServiceTest; import org.gringlobal.test.base.AbstractServiceTest;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -161,6 +163,11 @@ public abstract class AbstractServicesTest extends AbstractServiceTest { ...@@ -161,6 +163,11 @@ public abstract class AbstractServicesTest extends AbstractServiceTest {
@Autowired @Autowired
protected InventoryViabilityRepository inventoryViabilityRepository; protected InventoryViabilityRepository inventoryViabilityRepository;
@Autowired
protected AppSettingsService appSettingsService;
@Autowired
protected AppSettingRepository appSettingRepository;
@Override @Override
public void beforeTest() throws Exception { public void beforeTest() throws Exception {
super.beforeTest(); super.beforeTest();
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.gringlobal.test.service; package org.gringlobal.test.service;
import static org.gringlobal.model.community.CommunityAppSettings.BARCODE_INVENTORY;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
...@@ -66,6 +67,7 @@ public class InventoryServiceTest extends AbstractServicesTest { ...@@ -66,6 +67,7 @@ public class InventoryServiceTest extends AbstractServicesTest {
taxonomySpeciesRepository.deleteAll(); taxonomySpeciesRepository.deleteAll();
taxonomyGenusRepository.deleteAll(); taxonomyGenusRepository.deleteAll();
taxonomyFamilyRepository.deleteAll(); taxonomyFamilyRepository.deleteAll();
appSettingRepository.deleteAllInBatch();
super.cleanup(); super.cleanup();
} }
...@@ -611,4 +613,35 @@ public class InventoryServiceTest extends AbstractServicesTest { ...@@ -611,4 +613,35 @@ public class InventoryServiceTest extends AbstractServicesTest {
inventoryService.assignMissingInventoryNumbers(); inventoryService.assignMissingInventoryNumbers();
} }
@Test
public void assignBarcode() throws Exception {
asAdmin(() -> {
appSettingsService.ensureAppSetting(BARCODE_INVENTORY.categoryTag, BARCODE_INVENTORY.name, "{{ randomUUID }}");
return true;
});
Accession accession = addAccessionToDB();
var systemInventory = inventoryRepository.getSystemInventory(accession);
assertThat(systemInventory, notNullValue());
assertThat(systemInventory.getBarcode(), nullValue());
var inventory = addInventoryToDB(accession, INVENTORY_NUMBER_PART1_DEFAULT, null, null);
assertThat(inventory, notNullValue());
assertThat(inventory.getBarcode(), nullValue());
// Assert that system inventories don't get a barcode
assertThrows("System inventories do not have barcodes", InvalidApiUsageException.class, () -> {
inventoryService.assignBarcode(systemInventory);
});
// Assign a barcode
var barcode = inventoryService.assignBarcode(inventory);
assertThat(barcode, not(nullValue()));
inventory = inventoryService.get(inventory.getId()); // Reload
assertThat(inventory.getBarcode(), is(barcode));
// Existing barcode is returned
assertThat(inventoryService.assignBarcode(inventory), is(barcode));
}
} }
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