Commit 008373eb authored by Alina Habibulina's avatar Alina Habibulina

[FIX] испраления в справчониках, ссылках на реестр. добавлена api для...

[FIX] испраления в справчониках, ссылках на реестр. добавлена api для просмотре информации о результатах импорта
parent 8c259785
package kz.arta.ext.sap;
import javax.ejb.Singleton;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
public class State {
public volatile AtomicInteger imported = new AtomicInteger();
public volatile AtomicInteger count = new AtomicInteger();
public int totalAmount;
public volatile List<String> errors = new ArrayList<>();
public State(){}
public State(int totalAmount){
this.totalAmount = totalAmount;
imported.set(0);
count.set(0);
errors = new ArrayList<>();
}
public String toJSON(){
String json = "";
json += "{";
json += "\"total\": " + totalAmount + ", ";
json += "\"imported\": " + imported + ", ";
json += "\"count\": " + count + ", ";
json += "\"errors\": [";
for(String str : errors){
json += "\"" + str + "\", ";
}
json += "]";
json += "}";
return json;
}
}
package kz.arta.ext.sap.service; package kz.arta.ext.sap.service;
import kz.arta.ext.sap.State;
import kz.arta.ext.sap.util.ImportBean; import kz.arta.ext.sap.util.ImportBean;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
...@@ -10,6 +11,7 @@ import org.slf4j.Logger; ...@@ -10,6 +11,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.net.ssl.SSLEngineResult;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
...@@ -32,6 +34,7 @@ import java.util.Map; ...@@ -32,6 +34,7 @@ import java.util.Map;
public class UnsecuredProxyService { public class UnsecuredProxyService {
private static final Logger LOGGER = LoggerFactory.getLogger(UnsecuredProxyService.class); private static final Logger LOGGER = LoggerFactory.getLogger(UnsecuredProxyService.class);
private static State importState = new State();
@GET @GET
@Path("/test") @Path("/test")
...@@ -40,6 +43,17 @@ public class UnsecuredProxyService { ...@@ -40,6 +43,17 @@ public class UnsecuredProxyService {
return "{\"status\":\"working\"}"; return "{\"status\":\"working\"}";
} }
@GET
@Path("/info")
@Produces(MediaType.APPLICATION_JSON + "; charset=utf-8")
public Response getImportInfo(){
try {
return Response.status(Response.Status.OK).entity(importState.toJSON()).build();
} catch (Exception e){
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
/** /**
* Импорт записей в реестр * Импорт записей в реестр
* @param req * @param req
...@@ -90,14 +104,14 @@ public class UnsecuredProxyService { ...@@ -90,14 +104,14 @@ public class UnsecuredProxyService {
LOGGER.info("File " + fileName + "was written!"); LOGGER.info("File " + fileName + "was written!");
result = ImportBean.parseFile(fileName, formcode, registryCode, isActivate, login, password, action, defaultValue, searchString, shouldPasteMeaningValue); importState = ImportBean.parseFile(fileName, formcode, registryCode, isActivate, login, password, action, defaultValue, searchString, shouldPasteMeaningValue);
} }
} catch (Exception e){ } catch (Exception e){
LOGGER.error(e.getMessage()); LOGGER.error(e.getMessage());
return Response.status(500).entity(e.getMessage()).build(); return Response.status(500).entity(e.getMessage()).build();
} }
return Response.status(200).entity(result).build(); return Response.status(200).entity("Начат иморт записей реестра").build();
} }
......
Markdown is supported
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