Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vasgat committed Jan 29, 2021
1 parent dd83876 commit 4458c9b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
import certh.iti.mklab.easie.MongoUtils;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;

import java.net.UnknownHostException;
import java.util.ArrayList;

import org.bson.Document;
import org.bson.types.ObjectId;

/**
*
* @author vasgat
*/
public class CompanyMatcher {
Expand All @@ -38,14 +39,15 @@ public class CompanyMatcher {

/**
* Creates a Company object that connects the Company Name and Website with
* an entry from the dataset or creates a new one
* * an entry from the dataset or creates a new one
*
* @param CompanyName the name of the Company
* @param mongo a MongoUtils object
* @param CompanyLink the Website of the company
* @param dbname database's name
* @param collection's name
* @param searcher A CompanySearcher2 object
* @param company_name
* @param country
* @param website
* @param companies_collection
* @param searcher
* @param loader
* @throws UnknownHostException
*/
public CompanyMatcher(String company_name, String country, String website, MongoCollection companies_collection, CompanySearcher searcher, CountryAbreviationsLoader loader) throws UnknownHostException {
this.company_name = company_name.trim();
Expand Down Expand Up @@ -99,8 +101,8 @@ public void insertInfo(String fieldName, String fieldValue) {
companies.updateOne(new Document("_id", company_id),
new Document("$set",
new Document()
.append(fieldName.trim(),
fieldValue.trim())));
.append(fieldName.trim(),
fieldValue.trim())));
}
}

Expand Down Expand Up @@ -169,13 +171,13 @@ private ObjectId findCompanyId(String CompanyName, String CLink, String Country)
companies.updateOne(new Document("_id", tempId),
new Document("$set",
new Document()
.append("aliases",
aliases)));
.append("aliases",
aliases)));
companies.updateOne(new Document("_id", tempId),
new Document("$set",
new Document()
.append("website",
CLink.toLowerCase())));
.append("website",
CLink.toLowerCase())));
}
} else {
tempId = null;
Expand All @@ -191,8 +193,8 @@ private ObjectId findCompanyId(String CompanyName, String CLink, String Country)
companies.updateOne(new Document("_id", tempId),
new Document("$set",
new Document()
.append("aliases",
aliases)));
.append("aliases",
aliases)));
}
}
return tempId;
Expand All @@ -202,19 +204,19 @@ private ObjectId findCompanyId(String CompanyName, String CLink, String Country)
* Searches if the company exists to the database by having available only
* Company's name
*
* @returns company's id, if it is exists in db.
* @throws UnknownHostException
* @returns company's id, if it is exists in db.
*/
private ObjectId findCompanyId(String CompanyName, String Country) throws UnknownHostException {

ObjectId tempId = searcher.search(CompanyName, Country);
if (tempId != null) {
MongoCursor<Document> tempCursor = companies.find(
new Document()
.append(
"_id",
tempId
)
.append(
"_id",
tempId
)
).iterator();

ArrayList aliases = (ArrayList) tempCursor.next()
Expand All @@ -225,8 +227,8 @@ private ObjectId findCompanyId(String CompanyName, String Country) throws Unknow
companies.updateOne(new Document("_id", tempId),
new Document("$set",
new Document()
.append("aliases",
aliases)));
.append("aliases",
aliases)));
}
}
return tempId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,6 @@ public StaticHTMLFetcher(String baseURL, String relativeURL) throws URISyntaxExc
connection = Jsoup.connect(new URI(baseURL + relativeURL).toASCIIString()).followRedirects(true).ignoreHttpErrors(true)
.timeout(60000);
document = connection.get();
if ((baseURL + relativeURL).equals("https://elfar.cat/art/27043/el-amb-plantea-un-centenar-de-medidas-para-mejorar-la-movilidad-hasta-2024")) {
Writer writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("C:\\Users\\vasgat\\Desktop\\site2.json"), StandardCharsets.UTF_8));

org.bson.Document obj = new org.bson.Document();
obj.append("results", document.text());
writer.write(obj.toString());
writer.close();
Gson gson = new Gson();
System.out.println(org.apache.commons.lang3.StringEscapeUtils.unescapeJava(gson.toJson(obj)));
}
responseCode = connection.response().statusCode();
}

Expand All @@ -75,16 +64,6 @@ public StaticHTMLFetcher(String fullURL) throws URISyntaxException, IOException,
connection = Jsoup.connect(new URI(fullURL).toASCIIString()).followRedirects(true).ignoreHttpErrors(true)
.timeout(60000);
document = connection.get();
if ((fullURL).equals("https://elfar.cat/art/27043/el-amb-plantea-un-centenar-de-medidas-para-mejorar-la-movilidad-hasta-2024")) {
Writer writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("C:\\Users\\vasgat\\Desktop\\site2.json"), StandardCharsets.UTF_8));
org.bson.Document obj = new org.bson.Document();
obj.append("results", document.text());
writer.write(obj.toJson());
writer.close();
Gson gson = new Gson();
System.out.println(org.apache.commons.lang3.StringEscapeUtils.unescapeJava(gson.toJson(obj)));
}
responseCode = connection.response().statusCode();
}

Expand Down

0 comments on commit 4458c9b

Please sign in to comment.