Skip to content

Commit

Permalink
fix #248 code that filtered the install button has been removed, now …
Browse files Browse the repository at this point in the history
…it lets always to install app OR launch teh service. Fix #246 Now the cache get the get cities like Barcelona, Drome, etc and display them in the multi-select box.
  • Loading branch information
ilucatero committed Aug 31, 2015
1 parent 85ae80e commit f95c01d
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Repository;
import org.springframework.web.client.RestClientException;
import org.springframework.web.util.UriComponentsBuilder;

import com.mongodb.BasicDBObject;
import com.mongodb.BulkWriteOperation;
Expand Down Expand Up @@ -84,6 +83,9 @@ public class GeographicalAreaCache {
/** ex. Rhône-Alpes */
@Value("${application.geoarea.secondaryNameField:geo:name}")
private String nameField; // "geoci:name";
/** ex. "http://data.ozwillo.com/dc/type/geocifr:Commune_0/FR/FR-38/Saint-Clair-de-la-Tour" */
@Value("${application.geoarea.searchCronField:@id}")
private String searchCronField; // "@id";

@Autowired
private Tokenizer tokenizer;
Expand Down Expand Up @@ -165,12 +167,12 @@ private Stream<GeographicalArea> findOneToken(String country, String modelType,
// we search irrespective of the replication status, but we deduplicate based on DC Resource URI.
// sort spec means we want older results first - so that incoming replicates are discarded as long as
// there is an online entry
String encodedCountry = country;
try{
String encodedCountry = country; //comes already encoded
/*try{
encodedCountry = UriComponentsBuilder.fromUriString(country).build().encode().toString();
}catch(Exception e){
logger.debug("The country URI \"{}\" cannot be encoded : {}", country, e.toString());
}
}*/
Criteria criteria = where("lang").is(lang);
if (encodedCountry != null && !encodedCountry.trim().isEmpty()){
criteria.and("country").is(encodedCountry); //filter by country
Expand All @@ -182,8 +184,8 @@ private Stream<GeographicalArea> findOneToken(String country, String modelType,
criteria.and("nameTokens").regex(name);

return template.find(
query(criteria).with(new Sort(Sort.Direction.ASC, "replicationTime")),
GeographicalArea.class)
query(criteria).limit(100).with(new Sort(Sort.Direction.ASC, "replicationTime")),
GeographicalArea.class )
.stream()
.map(DCUrlWrapper::new)
.distinct()
Expand Down Expand Up @@ -225,11 +227,11 @@ public void replicate() {
portalSystemUserService.runAs(new Runnable() {
@Override
public void run() {
String lastNameFetched = null;
String lastDCIdFetched = null;
do {
logger.debug("Fetching batches of areas");
lastNameFetched = fetchBatches(collection, loadedUris, lastNameFetched);
} while (lastNameFetched != null);
lastDCIdFetched = fetchBatches(collection, loadedUris, lastDCIdFetched);
} while (lastDCIdFetched != null);
}
});

Expand All @@ -253,14 +255,15 @@ public void run() {

}

private String fetchBatches(DBCollection collection, Set<String> loadedUris, String lastNameFetched) {
private String fetchBatches(DBCollection collection, Set<String> loadedUris, String lastDCIdFetched) {

BulkWriteOperation builder = collection.initializeUnorderedBulkOperation();
String prevDcId = lastDCIdFetched;

DCQueryParameters params;
params = lastNameFetched == null
? new DCQueryParameters(nameField, DCOrdering.DESCENDING)
: new DCQueryParameters(nameField, DCOrdering.DESCENDING, DCOperator.LT, lastNameFetched);
params = lastDCIdFetched == null
? new DCQueryParameters(searchCronField, DCOrdering.DESCENDING)
: new DCQueryParameters(searchCronField, DCOrdering.DESCENDING, DCOperator.LT, "\""+lastDCIdFetched+"\"");
// (LT & descending order to leave possible null geo:name values at the end rather than having to skip them)

logger.debug("Querying the Data Core");
Expand All @@ -285,7 +288,7 @@ private String fetchBatches(DBCollection collection, Set<String> loadedUris, Str
hasOne = true;
if (name == null) {
name = area.getName();
logger.debug("{} - {}", name, area.getUri());
//logger.debug("{} - {}", name, area.getUri());
}

DBObject dbObject = new BasicDBObject();
Expand All @@ -300,10 +303,10 @@ private String fetchBatches(DBCollection collection, Set<String> loadedUris, Str
logger.debug("Area {} already inserted for language {}, skipping", area.getName(), language.getLanguage());
}
}

}

if (name != null) { lastNameFetched = name; }
String id = res.getUri(); // ID resource in DC is always encoded, so to match values we need to encoded as well
if (id != null) { lastDCIdFetched = id; }

}

Expand All @@ -314,8 +317,8 @@ private String fetchBatches(DBCollection collection, Set<String> loadedUris, Str
logger.debug("Saved resources; total save time={} ms (avg = {} ms)", durationSave, durationSave / resources.size());
}

if (resources.size() < batchSize) return null;
else return lastNameFetched;
if ( (prevDcId != null && prevDcId.equals(lastDCIdFetched)) || resources.size() < batchSize){ return null;}
else return lastDCIdFetched;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

@Document(collection = "geographical_area")
@CompoundIndexes({
@CompoundIndex(name = "lang_nametokens", def = "{'lang':1, 'nameTokens':1}")
@CompoundIndex(name = "lang_nametokens", def = "{'lang':1, 'nameTokens':1}"),
@CompoundIndex(name = "lang_nametokens_country", def = "{'lang':1, 'nameTokens':1, country:1}")
})
public class GeographicalArea {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.util.UriComponentsBuilder;

/**
* User: Ignacio
Expand Down Expand Up @@ -107,7 +106,8 @@ private List<DCResource> fetchResourceByCountryAndNameStartingWith(String queryT
String encodedCountryUri = countryUri;
try{
if(encodedCountryUri != null && !encodedCountryUri.isEmpty()){
encodedCountryUri = UriComponentsBuilder.fromUriString(countryUri).build().encode().toString();
//encodedCountryUri = UriComponentsBuilder.fromUriString(countryUri).build().encode().toString();
encodedCountryUri = countryUri;
params.and(countryField.trim(), DCOperator.EQ, encodedCountryUri);
}
}catch(Exception e){
Expand All @@ -132,7 +132,7 @@ public GeographicalArea toGeographicalArea(DCResource r, String language, String
}
String name = null;
for (Map<String, String> nameMap : nameMaps) {
logger.debug("nameMaps: " + nameMaps.toString());
//logger.debug("nameMaps: " + nameMaps.toString());
String l = nameMap.get("@language"); // TODO Q why ?? @language only in application/json+ld, otherwise l
if (l == null) { continue; /* shouldn't happen */ }
if (l.equals(language)) {
Expand All @@ -145,7 +145,9 @@ public GeographicalArea toGeographicalArea(DCResource r, String language, String
//TODO LATER: Create a full body DC interceptor to test request/response to DATACORE (similar to KernelLoggingInterceptor)
}

String country = r.getAsString("geoci:country");
String country = r.getAsString("geo:country"); /* The true value should be the main referenced model id (geo:country), but today
* it is not linked in the models. NB today it makes that some of the fields are not
* stored due to this field (been empty for those cases) */
List<String> modelType = r.getAsStringList("@type");

GeographicalArea area = new GeographicalArea();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public DCOrganization toDCOrganization(DCResource res, String language) {

String jurisdiction_uri = getBestI18nValue(res, language, "orgpu:jurisdiction", null);
String jurisdiction = jurisdiction_uri == null ? null : getBestI18nValue(
datacore.getResourceFromURI(dcOrgProjectName, jurisdiction_uri).getResource(), language, "geoci:displayName", null
datacore.getResourceFromURI(dcOrgProjectName, jurisdiction_uri).getResource(), language, "odisp:name", null
);

String phoneNumber = getBestI18nValue(res, language, "org:phoneNumber", null);
Expand All @@ -310,14 +310,14 @@ public DCOrganization toDCOrganization(DCResource res, String language) {
String POBox = getBestI18nValue(res, language, "adrpost:POBox", null);
String city_uri = getBestI18nValue(res, language, "adrpost:postName", null);
String city = city_uri == null ? null : getBestI18nValue(
datacore.getResourceFromURI(dcOrgProjectName, city_uri).getResource(), language, "geoci:displayName", null
datacore.getResourceFromURI(dcOrgProjectName, city_uri).getResource(), language, "odisp:name", null
);
String zip = getBestI18nValue(res, language, "adrpost:postCode", "org:postCode");
String cedex = getBestI18nValue(res, language, "adrpost:cedex", null);

String country_uri = getBestI18nValue(res, language, "adrpost:country", null);
String country = country_uri == null ? null : getBestI18nValue(
datacore.getResourceFromURI(dcOrgProjectName, country_uri).getResource(), language, "geoco:name", null
datacore.getResourceFromURI(dcOrgProjectName, country_uri).getResource(), language, "geo:name", null
);

//String longitude= getBestI18nValue(res, "org:longitude", null);
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,12 @@ var CountrySelect = React.createClass({
render: function() {
var label = this.props.defLabel;
if(!this.props.value || this.props.value === ""){
this.props.value = this.getValue(label); //This is to load the country_uri that couldn't be set
//This is to load the country_uri that couldn't be set |
this.props.value = (this.getValue(label)); // decodeURIComponent()
}
// the parameter "value=" is selected option. Default selected option can either be set here. Using browser-base fonctuion decodeURIComponent()
return ( <select className="btn btn-default dropdown-toggle" onChange={this.onChange}
value={decodeURIComponent(this.props.value)} disabled={this.props.disabled}>
value={this.props.value} disabled={this.props.disabled}>
{this.state.options}
</select>
);
Expand Down
Loading

0 comments on commit f95c01d

Please sign in to comment.