Skip to content
Merged
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 @@ -64,7 +64,7 @@ ResponseEntity getLostItem(@ApiParam(required = true) @PathVariable int id) thro
@ApiOperation(value = "", authorizations = {@Authorization(value="Authorization")})
@RequestMapping(value = "/lost/lostItems/{id}", method = RequestMethod.PUT)
public @ResponseBody
ResponseEntity updateLostItem(@ApiParam(value="(optional: type, title, location, date, content, state, phone, is_phone_open, thumbnail)", required = false) @RequestBody @Validated(ValidationGroups.Update.class) LostItem lostItem, BindingResult bindingResult, @ApiParam(required = true) @PathVariable int id) throws Exception {
ResponseEntity updateLostItem(@ApiParam(value="(required: type), (optional: title, location, date, content, state, phone, is_phone_open, thumbnail)", required = false) @RequestBody @Validated(ValidationGroups.Update.class) LostItem lostItem, BindingResult bindingResult, @ApiParam(required = true) @PathVariable int id) throws Exception {
LostItem clear = new LostItem();
return new ResponseEntity<LostItem>(lostAndFoundService.updateLostItem((LostItem) StringXssChecker.xssCheck(lostItem, clear), id), HttpStatus.CREATED);
}
Expand Down
73 changes: 39 additions & 34 deletions src/main/java/koreatech/in/schedule/BusTago.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package koreatech.in.schedule;

import com.google.gson.*;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import koreatech.in.domain.BusArrivalInfo;
import koreatech.in.domain.NotiSlack;
import koreatech.in.service.JsonConstructor;
import koreatech.in.util.SlackNotiSender;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -24,20 +25,6 @@

@Service("busTagoSchedule")
public class BusTago {
private String CACHE_KEY_BUS_ARRIVAL_INFO = "Tago@busArrivalInfo.%s.%s";

@Value("${OPEN_API_KEY}")
private static String OPEN_API_KEY;
@Value("${OPEN_API_KEY}")
private void setOpenApiKey(String key) { OPEN_API_KEY = key; }
public static String getOpenApiKey() { return OPEN_API_KEY; }

public int[] avaliableBus = {400, 401, 402, 493};

@Autowired
SlackNotiSender slackNotiSender;

private static String cityCode = "34010";
public static List<List<String>> nodeIds = new ArrayList<List<String>>() {{
add(new ArrayList<String>() {{
add("CAB285000405");
Expand All @@ -56,25 +43,31 @@ public class BusTago {
add("terminal");
}});
}};

private static String OPEN_API_KEY;
private static String cityCode = "34010";
private static ValueOperations<String, List<Map<String, Object>>> valueOps;
@Resource(name = "redisTemplate")
public void setValueOps(ValueOperations<String, List<Map<String, Object>>> _valueOps) {
valueOps = _valueOps;
}
public int[] avaliableBus = {400, 401, 402, 493};

private void updateAndCacheBusArrivalInfo(String cityCode, List<String> nodeId) throws IOException {
String cacheKey = getBusArrivalInfoCacheKey(cityCode, nodeId.get(0));
@Autowired
SlackNotiSender slackNotiSender;

List<Map<String, Object>> info = requestBusArrivalInfo(cityCode, nodeId);
private static JsonConstructor con;

valueOps.set(cacheKey, info);
private String CACHE_KEY_BUS_ARRIVAL_INFO = "Tago@busArrivalInfo.%s.%s";

@Value("${OPEN_API_KEY}")
private void setOpenApiKey(String key) {
OPEN_API_KEY = key;
}

@Autowired
private void setCon(JsonConstructor jsonConstructor) {
con = jsonConstructor;
}

private static List<Map<String, Object>> requestBusArrivalInfo(String cityCode, List<String> nodeId) throws IOException {

List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
JsonConstructor con = new JsonConstructor();

StringBuilder urlBuilder = new StringBuilder("http://openapi.tago.go.kr/openapi/service/ArvlInfoInqireService/getSttnAcctoArvlPrearngeInfoList"); /*URL*/
urlBuilder.append("?" + URLEncoder.encode("ServiceKey", "UTF-8") + "=" + OPEN_API_KEY); /*Service Key*/
Expand All @@ -101,9 +94,8 @@ private static List<Map<String, Object>> requestBusArrivalInfo(String cityCode,
}
rd.close();
conn.disconnect();
// System.out.println(sb.toString());

if (!con.isObjectParse(sb.toString())) return result;
if (!con.isJsonObject(sb.toString())) return result;

JsonObject nodeInfo = new JsonParser().parse(sb.toString()).getAsJsonObject();

Expand All @@ -114,24 +106,37 @@ private static List<Map<String, Object>> requestBusArrivalInfo(String cityCode,
int count = nodeInfo.getAsJsonObject("response").getAsJsonObject("body").get("totalCount").getAsInt();

Gson gson = new Gson();
if (count <=1) {
if (count <= 1) {
BusArrivalInfo col = new BusArrivalInfo();
if (count == 1) {
result.add(con.objectParse(nodeInfo.getAsJsonObject("response").getAsJsonObject("body").getAsJsonObject("items").getAsJsonObject("item")));
result.add(con.parseJsonObject(nodeInfo.getAsJsonObject("response").getAsJsonObject("body").getAsJsonObject("items").getAsJsonObject("item")));
}
return result;
}

result = con.arrayObjectParse(nodeInfo.getAsJsonObject("response").getAsJsonObject("body").getAsJsonObject("items").getAsJsonArray("item"));
result = con.parseJsonArrayWithObject(nodeInfo.getAsJsonObject("response").getAsJsonObject("body").getAsJsonObject("items").getAsJsonArray("item"));

return result;
}

@Resource(name = "redisTemplate")
public void setValueOps(ValueOperations<String, List<Map<String, Object>>> _valueOps) {
valueOps = _valueOps;
}

private void updateAndCacheBusArrivalInfo(String cityCode, List<String> nodeId) throws IOException {
String cacheKey = getBusArrivalInfoCacheKey(cityCode, nodeId.get(0));

List<Map<String, Object>> info = requestBusArrivalInfo(cityCode, nodeId);

valueOps.set(cacheKey, info);
}

@Scheduled(cron = "0 */1 * * * *")
public void handle() {
try {
for (List<String> nodeId: nodeIds) {
System.out.println("updating...("+cityCode+","+nodeId.get(0)+","+nodeId.get(1)+")\n");
for (List<String> nodeId : nodeIds) {
System.out.println("updating...(" + cityCode + "," + nodeId.get(0) + "," + nodeId.get(1) + ")\n");
updateAndCacheBusArrivalInfo(cityCode, nodeId);
}
} catch (NullPointerException e) {
Expand All @@ -153,7 +158,7 @@ private List<Map<String, Object>> getBusArrivalInfo(String cityCode, String node
}

public List<Map<String, Object>> getBusArrivalInfo(String nodeId) {
return getBusArrivalInfo(cityCode,nodeId);
return getBusArrivalInfo(cityCode, nodeId);
}

// private void sendError(Exception e) {
Expand Down
24 changes: 7 additions & 17 deletions src/main/java/koreatech/in/service/ActivityServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
import koreatech.in.exception.NotFoundException;
import koreatech.in.exception.PreconditionFailedException;
import koreatech.in.repository.ActivityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

import static koreatech.in.domain.DomainToMap.domainToMap;

Expand All @@ -22,6 +23,9 @@ public class ActivityServiceImpl implements ActivityService {
@Resource(name = "activityMapper")
private ActivityMapper activityMapper;

@Autowired
private JsonConstructor con;

@Override
public Map<String, Object> getActivities(String year) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
Expand All @@ -35,16 +39,9 @@ public Map<String, Object> getActivities(String year) throws Exception {
List<Map<String, Object>> appendActivities = new ArrayList<Map<String, Object>>();

Map<String, Object> convertActivity;
JsonConstructor con = new JsonConstructor();
for(Activity activity : activities) {
convertActivity = domainToMap(activity);

if (activity.getImage_urls() != null && !activity.getImage_urls().isEmpty()) {
try {
convertActivity.replace("image_urls", con.arrayStringParse(activity.getImage_urls()));
} catch (Exception e) {
}
}
convertActivity.replace("image_urls", con.parseJsonArrayWithOnlyString(activity.getImage_urls()));

appendActivities.add(convertActivity);
}
Expand All @@ -68,16 +65,9 @@ public Map<String, Object> getActivitiesForAdmin(String year) throws Exception {
List<Map<String, Object>> appendActivities = new ArrayList<Map<String, Object>>();

Map<String, Object> convertActivity;
JsonConstructor con = new JsonConstructor();
for(Activity activity : activities) {
convertActivity = domainToMap(activity);

if (activity.getImage_urls() != null && !activity.getImage_urls().isEmpty()) {
try {
convertActivity.replace("image_urls", con.arrayStringParse(activity.getImage_urls()));
} catch (Exception e) {
}
}
convertActivity.replace("image_urls", con.parseJsonArrayWithOnlyString(activity.getImage_urls()));

appendActivities.add(convertActivity);
}
Expand Down
31 changes: 9 additions & 22 deletions src/main/java/koreatech/in/service/CircleServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
import koreatech.in.domain.Circle.Circle;
import koreatech.in.domain.Circle.CircleResponseType;
import koreatech.in.domain.Criteria.Criteria;
import koreatech.in.domain.DomainToMap;
import koreatech.in.domain.ErrorMessage;
import koreatech.in.domain.Faq.Faq;
import koreatech.in.domain.Faq.FaqResponseType;
import koreatech.in.domain.User.User;
import koreatech.in.exception.*;
import koreatech.in.repository.CircleMapper;
import koreatech.in.repository.FaqMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.inject.Inject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -31,8 +30,8 @@ public class CircleServiceImpl implements CircleService {
@Inject
FaqMapper faqMapper;

@Inject
JwtValidator jwtValidator;
@Autowired
private JsonConstructor con;

@Override
public Map<String, Object> getCirclesForAdmin(Criteria criteria) throws Exception {
Expand Down Expand Up @@ -64,11 +63,9 @@ public Circle createCircleForAdmin(Circle circle) throws Exception {
throw new ConflictException(new ErrorMessage("exists circle name", 0));
}

JsonConstructor con = new JsonConstructor();
//link_urls 체크
if(circle.getLink_urls() != null && !circle.getLink_urls().isEmpty())
if(con.isArrayObjectParse(circle.getLink_urls()))
throw new PreconditionFailedException(new ErrorMessage("Image_urls are not valid", 0));
if(!con.isJsonArrayWithOnlyObject(circle.getLink_urls()))
throw new PreconditionFailedException(new ErrorMessage("Image_urls are not valid", 0));

if (circle.getIs_deleted() == null) {
circle.setIs_deleted(false);
Expand Down Expand Up @@ -121,15 +118,7 @@ public Map<String, Object> getCircle(int page, int limit, int id) throws Excepti
faq.put("totalPage", faqTotalPage);
faq.put("totalItemCount", faqTotalCount);

if(circle.getLink_urls() != null && !circle.getLink_urls().isEmpty()) {
JsonConstructor con = new JsonConstructor();
//link_urls 컬럼을 list로
try {
//link_url 리스트를 JsonArray로 변환하고 다시 for문으로 하나씩 map으로 변환해 새 리스트에 add
map.replace("link_urls", con.arrayObjectParse(circle.getLink_urls()));
} catch (Exception e) {
}
}
map.replace("link_urls", con.parseJsonArrayWithObject(circle.getLink_urls()));
map.put("faq", faq);

return map;
Expand Down Expand Up @@ -162,11 +151,9 @@ public Circle updateCircleForAdmin(Circle circle, int id) throws Exception {
throw new PreconditionFailedException(new ErrorMessage("invalid category name", 1));
}

JsonConstructor con = new JsonConstructor();
//link_urls 체크
if(circle.getLink_urls() != null && !circle.getLink_urls().isEmpty())
if(!con.isArrayObjectParse(circle.getLink_urls()))
throw new PreconditionFailedException(new ErrorMessage("link_urls are not valid", 0));
if(!con.isJsonArrayWithOnlyObject(circle.getLink_urls()))
throw new PreconditionFailedException(new ErrorMessage("link_urls are not valid", 0));

selectCircle.update(circle);
circleMapper.updateCircleForAdmin(selectCircle);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/koreatech/in/service/DiningServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import koreatech.in.domain.ErrorMessage;
import koreatech.in.exception.PreconditionFailedException;
import koreatech.in.repository.DiningMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.inject.Inject;
Expand All @@ -22,6 +23,9 @@ public class DiningServiceImpl implements DiningService {
@Inject
DiningMapper diningMapper;

@Autowired
private JsonConstructor con;

@Override
public List<Map<String, Object>> getDinings(String from) throws Exception {
LocalDate localDate;
Expand All @@ -36,13 +40,9 @@ public List<Map<String, Object>> getDinings(String from) throws Exception {
List<DiningMenu> dinings = diningMapper.getList(localDate.format(DateTimeFormatter.ISO_DATE));
List<Map<String, Object>> menus = new ArrayList<>();

JsonConstructor con = new JsonConstructor();
for (DiningMenu dining : dinings) {
Map<String, Object> convertMenu = domainToMap(dining);
try {
convertMenu.replace("menu", con.arrayStringParse(dining.getMenu()));
} catch (Exception e) {
}
convertMenu.replace("menu", con.parseJsonArrayWithOnlyString(dining.getMenu()));
menus.add(convertMenu);
}

Expand Down
Loading