Moving OA Soap Wrapper into current trunk version

git-svn-id: https://brutex.net/svn/xservices/trunk@188 e7e49efb-446e-492e-b9ec-fcafc1997a86
master
Brian Rosenberger 2018-08-22 07:36:37 +00:00
parent 1acb30d0ed
commit 5aba84c316
2 changed files with 137 additions and 0 deletions

View File

@ -0,0 +1,49 @@
/*
* Copyright 2013 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.brutex.xservices.ws.rs;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
/**
* The OpenAirInfoService Rest Service.
*
* @author Brian Rosenberger, bru(at)brutex.de
*/
@Path("/OpenAirInfoService/")
@Produces({ "text/xml" })
public abstract interface OpenAirInfoService {
public final static String BASE_PATH = "/OpenAirInfoService/";
public final static String SERVICE_NAME = "OpenAirInfoService";
@GET
@Path("getCompanies/")
//@Produces("application/octet-stream")
public abstract Response getCompanies(
@Context HttpHeaders paramHttpHeaders,
@QueryParam("search") String search);
}

View File

@ -0,0 +1,88 @@
package net.brutex.xservices.ws.rs;
import java.net.URL;
import java.util.GregorianCalendar;
import java.util.List;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.jcs.JCS;
import org.apache.commons.jcs.access.exception.CacheException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import net.brutex.mgmt.api.xml.Customer;
import net.brutex.mgmt.api.xml.DateFilter;
import net.brutex.mgmt.api.xml.Query;
import net.brutex.mgmt.api.xml.Query.BOOL;
import net.brutex.mgmt.api.xml.StringEntity;
import net.brutex.mgmt.openair.OpenAirRestConnection;
public class OpenAirInfoServiceImpl implements OpenAirInfoService {
static final Logger logger = LogManager.getLogger();
@Override
public Response getCompanies(HttpHeaders paramHttpHeaders, String search) {
OpenAirRestConnection con = getOpenAirConnection();
Query query = new Query(Customer.class);
query.addQuery("Address_Country", new StringEntity(search), BOOL.AND);
query.addQuery("active", new StringEntity("1"), BOOL.AND);
DateFilter datefilter = new DateFilter("updated");
GregorianCalendar date = new GregorianCalendar();
date.add(GregorianCalendar.MINUTE, -5);
datefilter.setStartdate(date);
query.addFilter(datefilter);
//query.addQuery("CustomerAccountCode", new StringEntity(search), BOOL.OR);
List<Customer> resultlist = (List<Customer>) con.getEntitiesByQuery(query);
GenericEntity generic = new GenericEntity<List<Customer>>(resultlist) {};
Response response = Response.ok(generic).build();
return response;
}
private OpenAirRestConnection getOpenAirConnection() {
/*
* get details from configuration file
*/
final PropertiesConfiguration props;
try {
final String config = "../openair.properties";
logger.debug("Loading Open Air connection details from " + this.getClass().getClassLoader().getResource("/")
+ config);
final URL configloc = this.getClass().getClassLoader().getResource(config);
props = new PropertiesConfiguration(configloc);
final String user = props.getString("user");
final String password = props.getString("password");
final String company = props.getString("company");
final String apikey = props.getString("apikey", "9x7G49ENkLCJ81i9XZJU");
final String namespace = props.getString("namespace");
final OpenAirRestConnection con;
con = new OpenAirRestConnection(JCS.getInstance("FileCache"), company, user, password);
return con;
} catch (CacheException e) {
logger.error(e);
e.printStackTrace();
} catch (ConfigurationException e) {
logger.error(e);
e.printStackTrace();
} finally {
}
return null;
}
}