Commit 21d8e4d9 authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch '287-application-startup' into 'main'

Resolve "Application startup"

Closes #287

See merge request grin-global/grin-global-server!378
parents 08fedc38 c43e5090
......@@ -415,7 +415,7 @@ public class ApplicationStartup implements InitializingBean {
String frontendOrigin = null;
try {
var frontend = new URL(frontendUrl);
if (frontend.getPort() != frontend.getDefaultPort()) {
if (frontend.getPort() != frontend.getDefaultPort() && frontend.getPort() != -1) {
frontendOrigin = String.format("%s://%s:%s", frontend.getProtocol(), frontend.getHost(), frontend.getPort());
} else {
frontendOrigin = String.format("%s://%s", frontend.getProtocol(), frontend.getHost());
......@@ -424,6 +424,17 @@ public class ApplicationStartup implements InitializingBean {
LOG.error("Invalid frontend URL {}", frontendUrl, e);
return;
}
String baseUrlOrigin = baseUrl;
try {
var base = new URL(baseUrlOrigin);
if (base.getPort() != base.getDefaultPort() && base.getPort() != -1) {
baseUrlOrigin = String.format("%s://%s:%s", base.getProtocol(), base.getHost(), base.getPort());
} else {
baseUrlOrigin = String.format("%s://%s", base.getProtocol(), base.getHost());
}
} catch (Exception e) {
LOG.error("Invalid base URL for origin {}", baseUrl, e);
}
if (oauthClientRepository.count() == 0) {
LOG.warn("Creating default OAuth client {}", defaultOAuthClientId);
......@@ -445,7 +456,7 @@ public class ApplicationStartup implements InitializingBean {
client.getRegisteredRedirectUri().add("oob");
client.getRegisteredRedirectUri().add(baseUrl + "/swagger-ui/oauth2-redirect.html");
client.getAllowedOrigins().add(baseUrl);
client.getAllowedOrigins().add(baseUrlOrigin);
if (StringUtils.isNotEmpty(frontendOrigin)) {
client.getAllowedOrigins().add(frontendOrigin);
}
......@@ -457,7 +468,7 @@ public class ApplicationStartup implements InitializingBean {
OAuthClient client = oauthClientRepository.findByClientId(defaultOAuthClientId);
if (client != null) {
// client.getAllowedOrigins().clear();
client.getAllowedOrigins().add(baseUrl);
client.getAllowedOrigins().add(baseUrlOrigin);
client.getAllowedOrigins().add(frontendOrigin);
client.getAllowedOrigins().add("http://localhost:3000");
// client.getRegisteredRedirectUri().clear();
......
......@@ -23,6 +23,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -30,11 +31,14 @@ import org.genesys.taxonomy.gringlobal.component.CabReader;
import org.genesys.taxonomy.gringlobal.model.GeographyRegionMapRow;
import org.genesys.taxonomy.gringlobal.model.GeographyRow;
import org.genesys.taxonomy.gringlobal.model.RegionRow;
import org.gringlobal.model.CodeValue;
import org.gringlobal.model.Geography;
import org.gringlobal.model.GeographyRegionMap;
import org.gringlobal.model.QCodeValue;
import org.gringlobal.model.Region;
import org.gringlobal.model.TaxonomySpecies;
import org.gringlobal.model.community.CommunityCodeValues;
import org.gringlobal.persistence.CodeValueRepository;
import org.gringlobal.persistence.GeographyRegionMapRepository;
import org.gringlobal.persistence.GeographyRepository;
import org.gringlobal.persistence.RegionRepository;
......@@ -69,6 +73,8 @@ public class UsdaGeographyUpdater {
private GeographyRegionMapRepository geoRegionRepository;
@Autowired
private CodeValueService codeValueService;
@Autowired
private CodeValueRepository codeValueRepository;
private final File downloadFolder = new File(FileUtils.getTempDirectory(), "grin-taxonomy-source"); // + System.currentTimeMillis());
......@@ -180,12 +186,20 @@ public class UsdaGeographyUpdater {
});
final List<Geography> toSave = new ArrayList<>();
var adm1TypeCodeValues = StreamSupport.stream(codeValueRepository.findAll(QCodeValue.codeValue.groupName.eq("GEOGRAPHY_ADMIN1_TYPE")).spliterator(), false)
.map(CodeValue::getValue)
.collect(Collectors.toList());
for (GeographyRow geographyRow : ggGeo) {
Geography geography = new Geography();
geography.setCountryCode(geographyRow.countryCode);
geography.setAdm1(geographyRow.adm1);
geography.setAdm1TypeCode(geographyRow.adm1TypeCode);
if (StringUtils.isNotBlank(geography.getAdm1TypeCode()) && !adm1TypeCodeValues.contains(geography.getAdm1TypeCode())) {
LOG.error("Invalid GEOGRAPHY_ADMIN1_TYPE: {}", geography.getAdm1TypeCode());
continue;
}
geography.setAdm2(geographyRow.adm2);
geography.setAdm3(geographyRow.adm3);
geography.setAdm4(geographyRow.adm4);
......
......@@ -2371,3 +2371,4 @@
4999 TAXONOMY_NOXIOUS_TYPE FWE 2019-11-21 21:03:19 48 \N \N 2019-11-21 21:03:19 48
5000 TAXONOMY_NOXIOUS_TYPE FWT 2019-11-21 21:03:19 48 \N \N 2019-11-21 21:03:19 48
5001 TAXONOMY_NOXIOUS_TYPE NARCOTIC 2019-11-21 21:36:36 48 \N \N 2019-11-21 21:36:36 48
5002 TAXONOMY_SPECIES_QUALIFIER I 2019-12-02 15:32:24 48 \N \N 2019-12-02 15:32:24 48
......@@ -8388,3 +8388,5 @@
13956 4999 1 Fish & Wildlife Endangered species Federally listed endangered species 2019-11-21 21:03:19 48 2019-11-21 21:56:49 48 2019-11-21 21:03:19 48
13957 5000 1 Fish & Wildlife Threatened species Federally listed threatened species 2019-11-21 21:03:19 48 2019-11-21 21:56:49 48 2019-11-21 21:03:19 48
13958 5001 1 Narcotic production use Restricted as source of narcotics 2019-11-21 21:36:36 48 2019-11-21 21:56:49 48 2019-11-21 21:36:36 48
13959 5002 1 Invalid An associated designation that was not validly published 2019-12-02 15:32:24 48 \N \N 2019-12-02 15:32:24 48
13960 5002 9 Invalid An associated designation that was not validly published 2019-12-02 15:32:24 48 \N \N 2019-12-02 15:32:24 48
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