Commit 9032954f authored by Alina Habibulina's avatar Alina Habibulina

[#1] Version 1

parent 84852be4
Pipeline #183 failed with stages
apply plugin: 'war'
sourceCompatibility = 1.7
version = '1.0'
sourceCompatibility = 1.8
task wrapper(type: Wrapper) {
gradleVersion = '4.6'
......@@ -13,21 +12,24 @@ repositories {
}
dependencies {
providedCompile(group: 'org.slf4j', name: 'slf4j-api', version: '1.6.1', transitive: false)
providedCompile(group: 'org.codehaus.jackson', name: 'jackson-core-asl', version: '1.9.2', transitive: false)
providedCompile(group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.9.2', transitive: false)
compile(group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25', transitive: false)
compile 'org.apache.httpcomponents:httpclient:4.5.1'
providedCompile(group: 'org.jboss.resteasy', name: 'resteasy-jaxrs', version: '2.3.3.Final', transitive: false)
compile group: 'org.jboss.resteasy', name: 'resteasy-jaxrs', version: '3.8.0.Final'
// https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-multipart-provider
compile group: 'org.jboss.resteasy', name: 'resteasy-multipart-provider', version: '2.3.3.Final'
compile group: 'org.jboss.resteasy', name: 'resteasy-multipart-provider', version: '3.8.0.Final'
// https://mvnrepository.com/artifact/commons-io/commons-io
compile group: 'commons-io', name: 'commons-io', version: '2.6'
providedCompile 'org.jboss.spec:jboss-javaee-6.0:3.0.3.Final'
compile ('org.jboss.spec:jboss-javaee-7.0:1.1.1.Final')
// https://mvnrepository.com/artifact/org.apache.poi/poi
providedCompile group: 'org.jboss.spec.javax.ejb', name: 'jboss-ejb-api_3.2_spec', version: '1.0.1.Final'
providedCompile group: 'org.jboss.spec.javax.ejb', name: 'jboss-ejb-api_3.2_spec', version: '1.0.2.Final'
compile group: 'org.apache.poi', name: 'poi', version: '3.9'
// https://mvnrepository.com/artifact/com.google.code.gson/gson
compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
// https://mvnrepository.com/artifact/joda-time/joda-time
compile group: 'joda-time', name: 'joda-time', version: '2.3'
compile group: 'joda-time', name: 'joda-time', version: '2.10.3'
// https://mvnrepository.com/artifact/org.json/json
compile group: 'org.json', name: 'json', version: '20180813'
}
\ No newline at end of file
rootProject.name = 'registry-import'
rootProject.name = 'import'
......@@ -3,6 +3,6 @@ package kz.arta.ext.sap.service;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("import")
@ApplicationPath("api")
public class Activator extends Application {
}
......@@ -3,7 +3,7 @@ package kz.arta.ext.sap.service;
import org.jboss.resteasy.annotations.interception.Precedence;
import org.jboss.resteasy.annotations.interception.ServerInterceptor;
import org.jboss.resteasy.core.Headers;
import org.jboss.resteasy.core.ResourceMethod;
import org.jboss.resteasy.core.ResourceMethodInvoker;
import org.jboss.resteasy.core.ServerResponse;
import org.jboss.resteasy.spi.Failure;
import org.jboss.resteasy.spi.HttpRequest;
......@@ -32,8 +32,9 @@ public class SecurityInterceptor implements PreProcessInterceptor {
@Context
HttpServletResponse response;
@Override
public ServerResponse preProcess(HttpRequest httpRequest, ResourceMethod resourceMethod) throws Failure, WebApplicationException {
public ServerResponse preProcess(HttpRequest request, ResourceMethodInvoker method) throws Failure, WebApplicationException {
return null;
}
}
package kz.arta.ext.sap.util;
import org.apache.http.annotation.ThreadSafe;
import java.util.Date;
@ThreadSafe
public interface DateFormat {
Date parse(String text) throws Exception;
Date parseStrict(String text) throws Exception;
......
package kz.arta.ext.sap.util;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
......@@ -46,21 +44,31 @@ public class HTTPRequestUtils {
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public static String sendPost(String url, String json, String login, String password) throws Exception {
HttpClient client = new DefaultHttpClient();
HttpPost request = new HttpPost(url);
PostMethod postMethod = new PostMethod(url);
org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient();
UsernamePasswordCredentials creds = new UsernamePasswordCredentials(login, password);
client.getParams().setAuthenticationPreemptive(true);
client.getState().setCredentials(org.apache.commons.httpclient.auth.AuthScope.ANY, creds);
postMethod.setRequestHeader("Content-type", "application/json; charset=utf-8");
postMethod.setRequestBody(json);
client.executeMethod(postMethod);
String answer = postMethod.getResponseBodyAsString();
postMethod.releaseConnection();
String usernameColonPassword = login + ":" + password;
String basicAuthPayload = "Basic " + Base64.encode(usernameColonPassword.getBytes("UTF-8"));
request.addHeader("Authorization", basicAuthPayload);
return answer;
request.setHeader("Content-type", "application/json; charset=utf-8");
StringEntity entity = new StringEntity(json);
request.setEntity(entity);
}
client.execute(request);
HttpResponse response = client.execute(request);
BufferedReader rd = new BufferedReader(
new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
return result.toString();
}
}
......@@ -3,6 +3,7 @@ package kz.arta.ext.sap.util;
import com.google.gson.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -115,24 +116,22 @@ public class ImportBean {
//добавляем поля в json
//ПОКА ЧТО Я НЕ РЕАЛИЗОВАЛА ИХ ПАРСИНГ И ФОРМАТИРОВАНИЕ
jsonData += "{ \"id\": \"" + ff.getCode() + "\", \"type\": \"" + ff.getType() + "\"";
//jsonData += "{ \"id\": \"" + ff.getCode() + "\", \"type\": \"" + ff.getType() + "\", \"value\": \"" + ff.getValue() + "\"";
jsonData += "{ \"id\": " + JSONObject.quote(ff.getCode()) + ", \"type\": " + JSONObject.quote(ff.getType());
//если это словарь и не чек бокс, нужно просто задать ему значение key
if(ff.getType().equals(FormFieldType.LISTBOX.value)){
jsonData += ", \"key\": \"" + ff.getKey() + "\", \"value\": \"" + ff.getValue() + "\"";
jsonData += ", \"key\": " + JSONObject.quote(ff.getKey()) + ", \"value\": " + JSONObject.quote(ff.getValue());
} else if(ff.getType().equals(FormFieldType.RADIO.value)){
jsonData += ", \"key\": \"" + ff.getValue() + "\", \"value\": \"" + ff.getKey() + "\"";
jsonData += ", \"key\": " + JSONObject.quote(ff.getValue()) + ", \"value\": " + JSONObject.quote(ff.getKey());
} else if(ff.getType().equals(FormFieldType.CHECKBOX.value)){
jsonData += ", \"values\": [";
for(String key : ff.getKeys()){
jsonData += "\"" + key + "\"";
jsonData += JSONObject.quote(key);
if(key != ff.getKeys().get(ff.getKeys().size() - 1)){
jsonData += ", ";
......@@ -141,7 +140,7 @@ public class ImportBean {
jsonData += "], \"keys\": [";
for(String val : ff.getValues()){
jsonData += "\"" + val + "\"";
jsonData += JSONObject.quote(val);
if(val != ff.getValues().get(ff.getValues().size() - 1)){
jsonData += ", ";
......@@ -153,27 +152,27 @@ public class ImportBean {
} else if(ff.getType().equals(FormFieldType.NUMERICINPUT.value)){
jsonData += ", \"key\": \"" + ff.getValue() + "\", \"value\": \"" + ff.getValue() + "\"";
jsonData += ", \"key\": " + JSONObject.quote(ff.getValue()) + ", \"value\": " + JSONObject.quote(ff.getValue());
} else if(ff.getType().equals(FormFieldType.REGLINK.value)){
if(ff.getKey() != null) {
jsonData += ", \"key\": \"" + ff.getKey() + "\", \"value\": \"" + ff.getValue() + "\", \"valueID\": \"" + ff.getKey() + "\"";
jsonData += ", \"key\": " + JSONObject.quote(ff.getKey()) + ", \"value\": " + JSONObject.quote(ff.getValue()) + ", \"valueID\": " + JSONObject.quote(ff.getKey());
}
} else if(ff.getType().equals(FormFieldType.ENTITY.value)){
jsonData += ", \"value\": \"" + ff.getValue() + "\"";
jsonData += ", \"value\": " + JSONObject.quote(ff.getValue());
} else if(ff.getType().equals(FormFieldType.DATE.value)){
String value = formatDate(ff.getDateFormat(), ff.getKey());
jsonData += ", \"key\": \"" + ff.getKey() + "\", \"value\": \"" + value + "\"";
jsonData += ", \"key\": " + JSONObject.quote(ff.getKey()) + ", \"value\": " + JSONObject.quote(value);
} else { //если текстовое поле
jsonData += ", \"value\": \"" + ff.getValue() + "\"";
jsonData += ", \"value\": " + JSONObject.quote(ff.getValue());
}
......
<jboss umlns="urn:jboss:1.0">
<jboss-deployment-dependencies xmlns="urn:jboss:deployment-dependencies:1.0">
<dependency name="Synergy.ear" />
</jboss-deployment-dependencies>
</jboss>
\ No newline at end of file
<jboss-web>
<context-root>import</context-root>
</jboss-web>
\ No newline at end of file
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