Search in sources :

Example 6 with CallMethod

use of com.axelor.meta.CallMethod in project axelor-open-suite by axelor.

the class ImportDateTime method importDate.

@CallMethod
public String importDate(String inputDate) {
    String patDate = "(" + dt + "|TODAY)(\\[(" + String.format(pat, 4, "y") + "?" + String.format(pat, 2, "M") + "?" + String.format(pat, 2, "d") + "?" + ")\\])?";
    try {
        if (!Strings.isNullOrEmpty(inputDate) && inputDate.matches(patDate)) {
            List<String> dates = Arrays.asList(inputDate.split("\\["));
            inputDate = dates.get(0).equals("TODAY") ? Beans.get(AppBaseService.class).getTodayDate(Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null)).toString() : dates.get(0);
            if (dates.size() > 1) {
                LocalDateTime localDate = LocalDate.parse(inputDate, DateTimeFormatter.ISO_DATE).atStartOfDay();
                Matcher matcher = Pattern.compile(String.format(pat, 4, "y")).matcher(dates.get(1));
                if (matcher.find())
                    localDate = updateYear(localDate, matcher.group());
                matcher = Pattern.compile(String.format(pat, 2, "M")).matcher(dates.get(1));
                if (matcher.find())
                    localDate = updateMonth(localDate, matcher.group());
                matcher = Pattern.compile(String.format(pat, 2, "d")).matcher(dates.get(1));
                if (matcher.find())
                    localDate = updateDay(localDate, matcher.group());
                return localDate.toString();
            } else
                return inputDate;
        } else
            return null;
    } catch (Exception e) {
        return null;
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) Matcher(java.util.regex.Matcher) CallMethod(com.axelor.meta.CallMethod)

Example 7 with CallMethod

use of com.axelor.meta.CallMethod in project axelor-open-suite by axelor.

the class WkfDisplayServiceImpl method getInstanceUrl.

@Override
@CallMethod
public String getInstanceUrl(WkfInstance wkfInstance) {
    try {
        ProcessEngine engine = engineService.getEngine();
        String processInstanceId = wkfInstance.getInstanceId();
        List<String> activeIds = getActivityIds(processInstanceId);
        Map<String, Integer> activityCountMap = new HashMap<>();
        getActivityPassCount(wkfInstance.getInstanceId(), activityCountMap);
        WkfProcess wkfProcess = wkfInstance.getWkfProcess();
        BpmnModelInstance modelInstance = engine.getRepositoryService().getBpmnModelInstance(wkfProcess.getProcessId());
        Iterator<Process> processIter = modelInstance.getModelElementsByType(Process.class).iterator();
        HistoricVariableInstanceQuery variableQuery = engine.getHistoryService().createHistoricVariableInstanceQuery().processInstanceId(processInstanceId);
        while (processIter.hasNext()) {
            Process process = processIter.next();
            if (process.getId().equals(wkfProcess.getName())) {
                continue;
            }
            HistoricVariableInstance variableInstance = variableQuery.variableName(process.getId()).singleResult();
            if (variableInstance != null) {
                activeIds.addAll(getActivityIds((String) variableInstance.getValue()));
                getActivityPassCount((String) variableInstance.getValue(), activityCountMap);
            }
        }
        String activityCount = activityCountMap.keySet().stream().map(it -> it + ":" + activityCountMap.get(it)).collect(Collectors.joining(","));
        log.trace("Active node ids: {}", activeIds);
        String url = String.format(engineService.getWkfViewerUrl(), "instanceId=" + wkfInstance.getInstanceId(), Joiner.on(",").join(activeIds), activityCount);
        log.debug("Url created: {}", url);
        return url;
    } catch (Exception e) {
    }
    return null;
}
Also used : HistoryService(org.camunda.bpm.engine.HistoryService) CallMethod(com.axelor.meta.CallMethod) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) HistoricProcessInstanceQuery(org.camunda.bpm.engine.history.HistoricProcessInstanceQuery) ProcessEngineService(com.axelor.apps.bpm.service.init.ProcessEngineService) WkfInstanceRepository(com.axelor.apps.bpm.db.repo.WkfInstanceRepository) WkfInstanceService(com.axelor.apps.bpm.service.execution.WkfInstanceService) WkfInstance(com.axelor.apps.bpm.db.WkfInstance) Map(java.util.Map) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) HistoricVariableInstanceQuery(org.camunda.bpm.engine.history.HistoricVariableInstanceQuery) WkfTaskConfigRepository(com.axelor.apps.bpm.db.repo.WkfTaskConfigRepository) WkfModel(com.axelor.apps.bpm.db.WkfModel) JPA(com.axelor.db.JPA) Logger(org.slf4j.Logger) Model(com.axelor.db.Model) Iterator(java.util.Iterator) ActivityTypes(org.camunda.bpm.engine.ActivityTypes) Set(java.util.Set) ProcessEngine(org.camunda.bpm.engine.ProcessEngine) WkfProcess(com.axelor.apps.bpm.db.WkfProcess) Collectors(java.util.stream.Collectors) HistoricActivityInstance(org.camunda.bpm.engine.history.HistoricActivityInstance) List(java.util.List) Beans(com.axelor.inject.Beans) WkfTaskConfig(com.axelor.apps.bpm.db.WkfTaskConfig) Process(org.camunda.bpm.model.bpmn.instance.Process) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) RuntimeService(org.camunda.bpm.engine.RuntimeService) AuthUtils(com.axelor.auth.AuthUtils) User(com.axelor.auth.db.User) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord) Joiner(com.google.common.base.Joiner) HashMap(java.util.HashMap) WkfProcess(com.axelor.apps.bpm.db.WkfProcess) Process(org.camunda.bpm.model.bpmn.instance.Process) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) WkfProcess(com.axelor.apps.bpm.db.WkfProcess) HistoricVariableInstanceQuery(org.camunda.bpm.engine.history.HistoricVariableInstanceQuery) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) ProcessEngine(org.camunda.bpm.engine.ProcessEngine) CallMethod(com.axelor.meta.CallMethod)

Example 8 with CallMethod

use of com.axelor.meta.CallMethod in project axelor-open-suite by axelor.

the class ProductCompanyServiceImpl method get.

@Override
@CallMethod
public Object get(Product originalProduct, String fieldName, Company company) throws AxelorException {
    Mapper mapper = Mapper.of(Product.class);
    Product product = findAppropriateProductCompany(originalProduct, fieldName, company);
    return mapper.get(product, fieldName);
}
Also used : Mapper(com.axelor.db.mapper.Mapper) Product(com.axelor.apps.base.db.Product) CallMethod(com.axelor.meta.CallMethod)

Example 9 with CallMethod

use of com.axelor.meta.CallMethod in project axelor-open-suite by axelor.

the class ProductCompanyServiceImpl method set.

@Override
@CallMethod
public void set(Product originalProduct, String fieldName, Object fieldValue, Company company) throws AxelorException {
    Mapper mapper = Mapper.of(Product.class);
    Product product = findAppropriateProductCompany(originalProduct, fieldName, company);
    mapper.set(product, fieldName, fieldValue);
}
Also used : Mapper(com.axelor.db.mapper.Mapper) Product(com.axelor.apps.base.db.Product) CallMethod(com.axelor.meta.CallMethod)

Aggregations

CallMethod (com.axelor.meta.CallMethod)9 WkfInstance (com.axelor.apps.bpm.db.WkfInstance)3 WkfProcess (com.axelor.apps.bpm.db.WkfProcess)3 WkfTaskConfig (com.axelor.apps.bpm.db.WkfTaskConfig)3 WkfInstanceRepository (com.axelor.apps.bpm.db.repo.WkfInstanceRepository)3 WkfTaskConfigRepository (com.axelor.apps.bpm.db.repo.WkfTaskConfigRepository)3 ProcessEngineService (com.axelor.apps.bpm.service.init.ProcessEngineService)3 Model (com.axelor.db.Model)3 Beans (com.axelor.inject.Beans)3 MetaJsonRecord (com.axelor.meta.db.MetaJsonRecord)3 Inject (com.google.inject.Inject)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 HistoryService (org.camunda.bpm.engine.HistoryService)3 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)3 RuntimeService (org.camunda.bpm.engine.RuntimeService)3 HistoricActivityInstance (org.camunda.bpm.engine.history.HistoricActivityInstance)3