use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class HttpRequestSender method getSecuredHttpClient.
private DefaultHttpClient getSecuredHttpClient(Certificate cert, String bankURL) throws AxelorException {
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 30000);
HttpConnectionParams.setSoTimeout(httpParams, 30000);
DefaultHttpClient client = new DefaultHttpClient(httpParams);
try {
Scheme https = null;
if (cert != null) {
log.debug("SSL certificate exist");
URL url = new URL(bankURL);
log.debug("Url host: {}", url.getHost());
KeyStore keystore = KeyStore.getInstance("jks");
char[] password = "NoPassword".toCharArray();
keystore.load(null, password);
keystore.setCertificateEntry(url.getHost(), cert);
SSLSocketFactory factory = new SSLSocketFactory(keystore);
try {
factory.getHostnameVerifier().verify(url.getHost(), (X509Certificate) cert);
https = new Scheme("https", 443, new SSLSocketFactory(keystore));
} catch (SSLException e) {
log.debug("Error in ssl certifcate host name verification");
https = new Scheme("https", 443, SSLSocketFactory.getSocketFactory());
}
} else {
log.debug("SSL certificate not exist");
https = new Scheme("https", 443, SSLSocketFactory.getSocketFactory());
}
client.getConnectionManager().getSchemeRegistry().register(https);
} catch (Exception e) {
e.printStackTrace();
throw new AxelorException(e.getCause(), TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get("Error adding certificate"));
}
return client;
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class HttpRequestSender method send.
/**
* Sends the request contained in the <code>ContentFactory</code>. The <code>ContentFactory</code>
* will deliver the request as an <code>InputStream</code>.
*
* @param request the ebics request
* @return the HTTP return code
* @throws AxelorException
*/
public final int send(ContentFactory request) throws IOException, AxelorException {
EbicsBank bank = session.getUser().getEbicsPartner().getEbicsBank();
String url = bank.getUrl();
if (url == null || !url.startsWith("http://") && !url.startsWith("https://")) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.EBICS_INVALID_BANK_URL));
}
if (bank.getProtocolSelect().equals("ssl")) {
return sendSSL(request, bank);
} else {
return sendTLS(request, bank);
}
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class WkfCommonServiceImpl method findRelatedRecord.
@Override
public Object findRelatedRecord(Model model, String path) throws AxelorException {
Object object = null;
FullContext wkfModel = new FullContext(model);
if (path.startsWith("_find(")) {
List<String> params = Arrays.asList(path.replace("_find(", "").replace(")", "").split(","));
if (params.size() >= 2) {
List<Object> queryParams = params.stream().map(it -> evalExpression(wkfModel, it)).collect(Collectors.toList());
String queryModel = (String) queryParams.get(0);
queryParams.remove(0);
String query = (String) queryParams.get(0);
queryParams.remove(0);
log.debug("Find model: {}, query: {}, params: {}", queryModel, query, queryParams);
object = WkfContextHelper.filterOne(queryModel, query, queryParams.toArray());
}
} else {
object = evalExpression(new FullContext(model), path);
}
return object;
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class DmnExportServiceImpl method createHeaderRow.
private void createHeaderRow(Sheet sheet, DecisionTable table) throws AxelorException {
Row titleRow = sheet.createRow(sheet.getLastRowNum());
Cell titleCell = titleRow.createCell(0);
titleCell.setCellValue(table.getParentElement().getAttributeValue("name"));
sheet.autoSizeColumn(0);
Row row = sheet.createRow(sheet.getLastRowNum() + 1);
int inputIndex = 0;
for (Input input : table.getInputs()) {
if (Strings.isNullOrEmpty(input.getLabel())) {
throw new AxelorException(TraceBackRepository.CATEGORY_NO_VALUE, IExceptionMessage.MISSING_INPUT_LABEL);
}
Cell cell = row.createCell(inputIndex);
cell.setCellValue(input.getLabel() + "(" + input.getId() + ")");
sheet.autoSizeColumn(inputIndex);
inputIndex++;
}
int outputIndex = row.getLastCellNum();
for (Output output : table.getOutputs()) {
if (Strings.isNullOrEmpty(output.getLabel())) {
throw new AxelorException(TraceBackRepository.CATEGORY_NO_VALUE, IExceptionMessage.MISSING_OUTPUT_LABEL);
}
Cell cell = row.createCell(outputIndex);
cell.setCellValue(output.getLabel() + "(" + output.getId() + ")");
sheet.autoSizeColumn(outputIndex);
outputIndex++;
}
Cell cell = row.createCell(outputIndex);
cell.setCellValue("Annotation");
sheet.autoSizeColumn(outputIndex);
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class DmnImportServiceImpl method process.
@Transactional
public void process(DataReaderService reader, WkfDmnModel dmnModel) throws AxelorException {
DmnModelInstance dmnModelInstance = Dmn.readModelFromStream(new ByteArrayInputStream(dmnModel.getDiagramXml().getBytes()));
String[] sheets = reader.getSheetNames();
int counter = 1;
for (String sheet : sheets) {
DecisionTable table = this.getDecisionTable(sheet, dmnModelInstance);
if (table == null) {
continue;
}
int totalLines = reader.getTotalLines(sheet);
if (totalLines == 0) {
continue;
}
table.getRules().clear();
String[] headerRow = reader.read(sheet, 1, 0);
for (int i = 2; i < totalLines; i++) {
String[] row = reader.read(sheet, i, headerRow.length);
if (row == null || row.length == 0 || Arrays.asList(row).stream().noneMatch(Objects::nonNull)) {
continue;
}
Rule rule = dmnModelInstance.newInstance(Rule.class);
rule.setId(RULE + i + counter);
for (int j = 0; j < row.length; j++) {
String value = StringUtils.isBlank(row[j]) ? null : row[j].trim();
Object entryObj = this.checkEntry(headerRow, j, table, reader);
if (entryObj == null) {
continue;
}
rule = this.createEntries(entryObj, value, j, i, counter, rule, dmnModelInstance);
}
if (rule.getOutputEntries().isEmpty()) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, IExceptionMessage.EMPTY_OUTPUT_COLUMN);
}
table.getRules().add(rule);
}
counter++;
}
String diagramXml = Dmn.convertToString(dmnModelInstance);
diagramXml = diagramXml.replaceAll(SPACE_PATTERN, "");
dmnModel.setDiagramXml(diagramXml);
dmnModelRepo.save(dmnModel);
}
Aggregations