Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ public void update(Business business) {
if (!this.betterCottonMember) {
this.betterCottonMember = business.isBetterCottonMember();
}
if (this.id == null) {
if (this.id == null || this.id.equals("")) {
this.id = business.getId();
}
if (!this.bcorpCertified) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.appengine.springboot.business;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -21,4 +24,29 @@ public class BusinessController {
public Business getBusinessByWebsite(@PathVariable("company") String companyName, HttpServletResponse response) throws IOException {
return businessService.getBusinessByWebsite(companyName);
}

@GetMapping("/Business/getAll")
public List<Business> getAll() {
return businessService.getAll();
}

@PutMapping("/Business/insert")
public Business insert(@RequestBody Business business) {
return businessService.insert(business);
}

@PutMapping("/Business/insertAll")
public List<Business> insertAll(@RequestBody List<Business> businesses) {
return businessService.insertAll(businesses);
}

@PutMapping("/Business/update")
public Business update(@RequestBody Business business) {
return businessService.update(business);
}

@PutMapping("/Business/updateAll")
public List<Business> updateAll(@RequestBody List<Business> businesses) {
return businessService.updateAll(businesses);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.appengine.springboot.business;

import com.appengine.springboot.advertisement.Advertisement;
import java.util.List;
import java.util.Optional;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface BusinessRepository extends MongoRepository<Business, String> {

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.appengine.springboot.business;

import com.appengine.springboot.Tools;
import com.appengine.springboot.advertisement.AdvertisementRepository;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
Expand All @@ -18,9 +20,14 @@
@Service
public class BusinessService {

@Autowired
BusinessRepository businessRepository;

@Autowired
private MongoOperations mongoOperations;

List<Business> db;

public List<Business> regexWebsite(String website) {
Query query = new Query().addCriteria(Criteria.where("website").regex(website, "i"));
return mongoOperations.find(query, Business.class);
Expand All @@ -40,10 +47,6 @@ public Business getBusinessByWebsite(String companyName) throws IOException {
}
business.update(searchDataSource(companyName, "EPA's Green Power Partners - Sheet1.csv", 5, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, false, false, false, false, false, false, false, false, false, false, false, false));
business.update(searchDataSource(companyName, "Financial Contributions-Companies Supporting Black Lives.csv", 5, 0, -1, -1, -1, -1, -1, -1, -1, 4, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, false, true, false, false, false, false, false, false, false, false, false, false));
business.update(searchDataSource(companyName, "bluesign-reference-list.txt", 1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, true, false, false, false, false, false, false, false, false, false, false, false));
business.update(searchDataSource(companyName, "Cruelty-Free (Ethical Elephant Directory).csv", 5, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, false, false, false, false, false, false, true, false, false, false, false, false));
business.update(searchDataSource(companyName, "Companies that test on animals.csv", 2, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, false, false, false, false, false, false, false, false, false, false, true, false));
business.update(searchDataSource(companyName, "Leaping Bunny Approved Brands.csv", 3, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, false, false, false, false, false, false, false, false, false, false, false, true));
business.calculate();
}
return business;
Expand Down Expand Up @@ -274,4 +277,36 @@ public static Business searchDataSource(
}
return business;
}

public List<Business> getAll() {
return businessRepository.findAll();
}

public Business insert(Business business) {
return businessRepository.insert(business);
}

public List<Business> insertAll(List<Business> businesses) {
return businessRepository.insert(businesses);
}

public Business update(Business business) {
return businessRepository.save(business);
}

public List<Business> updateAll(List<Business> businesses) {
if (db == null) {
db = getAll();
}
for (int a = 0; a < businesses.size(); ++a) {
for (int b = 0; b < db.size(); ++b) {
if (businesses.get(a).getWebsite().equals(db.get(b).getWebsite())) {
businesses.get(a).setName(db.get(b).getName());
businesses.get(a).setWebsite(db.get(b).getWebsite());
businesses.get(a).update(db.get(b));
}
}
}
return businessRepository.saveAll(businesses);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ protected void configure(HttpSecurity http) throws Exception {
"/Advertisement/add",
"/Advertisement/addAll",
"/Advertisement/update",
"/Advertisement/delete")
"/Advertisement/delete",
"/Business/getAll",
"/Business/insert",
"/Business/insertAll",
"/Business/update",
"/Business/updateAll")
.hasRole("ADMIN")
.and()
.csrf()
Expand Down
Loading