Rev 198 | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
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 lombok.extern.slf4j.Slf4j;
import org.apache.commons.configuration2.PropertiesConfiguration;
import org.apache.commons.configuration2.builder.fluent.Configurations;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.apache.commons.jcs.JCS;
import org.apache.commons.jcs.access.exception.CacheException;
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;
@Slf4j
public class OpenAirInfoServiceImpl implements OpenAirInfoService {
@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
*/
Configurations configs = new Configurations();
final PropertiesConfiguration props;
try {
final String config = "../openair.properties";
log.debug("Loading Open Air connection details from '{}'.", this.getClass().getClassLoader().getResource("/")
+ config);
final URL configloc = this.getClass().getClassLoader().getResource(config);
props = configs.properties(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 | ConfigurationException e) {
log.error(e.getMessage());
e.printStackTrace();
} finally {
}
return null;
}
}