Search in sources :

Example 86 with AxelorException

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;
}
Also used : AxelorException(com.axelor.exception.AxelorException) BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) Scheme(org.apache.http.conn.scheme.Scheme) BasicHttpParams(org.apache.http.params.BasicHttpParams) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory) KeyStore(java.security.KeyStore) SSLException(javax.net.ssl.SSLException) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) URL(java.net.URL) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) SSLException(javax.net.ssl.SSLException)

Example 87 with AxelorException

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);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) EbicsBank(com.axelor.apps.bankpayment.db.EbicsBank)

Example 88 with AxelorException

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;
}
Also used : MetaJsonFieldRepository(com.axelor.meta.db.repo.MetaJsonFieldRepository) Arrays(java.util.Arrays) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) Variables(org.camunda.bpm.engine.variable.Variables) EntityHelper(com.axelor.db.EntityHelper) JpaRepository(com.axelor.db.JpaRepository) WkfModelRepository(com.axelor.apps.bpm.db.repo.WkfModelRepository) WkfProcessConfig(com.axelor.apps.bpm.db.WkfProcessConfig) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) Property(com.axelor.db.mapper.Property) GroovyScriptHelper(com.axelor.script.GroovyScriptHelper) HashMap(java.util.HashMap) Mapper(com.axelor.db.mapper.Mapper) FullContext(com.axelor.apps.tool.context.FullContext) Strings(com.google.common.base.Strings) AxelorException(com.axelor.exception.AxelorException) Map(java.util.Map) WkfContextHelper(com.axelor.apps.bpm.context.WkfContextHelper) StringTool(com.axelor.apps.tool.StringTool) Logger(org.slf4j.Logger) Model(com.axelor.db.Model) JPAVariableSerializer(org.camunda.bpm.engine.impl.variable.serializer.jpa.JPAVariableSerializer) BpmnParser(org.camunda.bpm.engine.impl.bpmn.parser.BpmnParser) ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) Collectors(java.util.stream.Collectors) SimpleBindings(javax.script.SimpleBindings) List(java.util.List) WkfProcessConfigRepository(com.axelor.apps.bpm.db.repo.WkfProcessConfigRepository) Context(com.axelor.rpc.Context) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord) SerializationDataFormats(org.camunda.bpm.engine.variable.Variables.SerializationDataFormats) FullContext(com.axelor.apps.tool.context.FullContext)

Example 89 with AxelorException

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);
}
Also used : AxelorException(com.axelor.exception.AxelorException) Input(org.camunda.bpm.model.dmn.instance.Input) Output(org.camunda.bpm.model.dmn.instance.Output) Row(org.apache.poi.ss.usermodel.Row) Cell(org.apache.poi.ss.usermodel.Cell)

Example 90 with AxelorException

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);
}
Also used : DecisionTable(org.camunda.bpm.model.dmn.instance.DecisionTable) AxelorException(com.axelor.exception.AxelorException) ByteArrayInputStream(java.io.ByteArrayInputStream) Rule(org.camunda.bpm.model.dmn.instance.Rule) DmnModelInstance(org.camunda.bpm.model.dmn.DmnModelInstance) Transactional(com.google.inject.persist.Transactional)

Aggregations

AxelorException (com.axelor.exception.AxelorException)546 Transactional (com.google.inject.persist.Transactional)126 BigDecimal (java.math.BigDecimal)118 ArrayList (java.util.ArrayList)84 IOException (java.io.IOException)73 Product (com.axelor.apps.base.db.Product)64 Company (com.axelor.apps.base.db.Company)63 LocalDate (java.time.LocalDate)58 Partner (com.axelor.apps.base.db.Partner)48 List (java.util.List)45 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)40 HashMap (java.util.HashMap)38 Invoice (com.axelor.apps.account.db.Invoice)33 StockMove (com.axelor.apps.stock.db.StockMove)32 Map (java.util.Map)31 Beans (com.axelor.inject.Beans)30 I18n (com.axelor.i18n.I18n)28 Inject (com.google.inject.Inject)28 MoveLine (com.axelor.apps.account.db.MoveLine)27 Context (com.axelor.rpc.Context)27