use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class SupplierViewController method getDeliveriesToPrepare.
public void getDeliveriesToPrepare(ActionRequest request, ActionResponse response) {
try {
SupplierViewService supplierViewService = Beans.get(SupplierViewService.class);
User user = supplierViewService.getSupplierUser();
String domain = Beans.get(SupplierViewService.class).getDeliveriesToPrepareOfSupplier(user);
response.setView(ActionView.define(I18n.get("Deliveries to prepare")).model(StockMove.class.getName()).add("grid", "stock-move-supplier-grid").add("form", "stock-move-supplier-form").domain(domain).map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class SupplierViewController method getLastDelivery.
/* StockMove OnClick*/
public void getLastDelivery(ActionRequest request, ActionResponse response) {
try {
SupplierViewService supplierViewService = Beans.get(SupplierViewService.class);
User user = supplierViewService.getSupplierUser();
String domain = Beans.get(SupplierViewService.class).getLastDeliveryOfSupplier(user);
StockMove stockMove = Beans.get(StockMoveRepository.class).all().filter(domain).fetchOne();
if (stockMove != null) {
response.setView(ActionView.define(I18n.get("Last delivery")).model(StockMove.class.getName()).add("form", "stock-move-supplier-form").domain(domain).context("_showRecord", stockMove.getId()).map());
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class BusinessProjectMobileController method getProjects.
/*
* This method is used in mobile application.
* It was in ProjectTaskBusinessServiceImpl
* @param request
* @param response
*
* POST /open-suite-webapp/ws/action/com.axelor.apps.businessproject.mobile.BusinessProjectMobileController:getProjects
* Content-Type: application/json
*
* URL: com.axelor.apps.businessproject.mobile.BusinessProjectMobileController:getProjects
* fields: no field
*
* payload:
* { "data": {
* "action": "com.axelor.apps.businessproject.mobile.BusinessProjectMobileController:getProjects"
* } }
*/
public void getProjects(ActionRequest request, ActionResponse response) {
List<Map<String, String>> dataList = new ArrayList<Map<String, String>>();
try {
User user = AuthUtils.getUser();
if (user != null) {
List<Project> projectList = Beans.get(ProjectRepository.class).all().filter("self.imputable = true").fetch();
for (Project project : projectList) {
if ((project.getMembersUserSet() != null && project.getMembersUserSet().contains(user)) || user.equals(project.getAssignedTo())) {
Map<String, String> map = new HashMap<String, String>();
map.put("name", project.getName());
map.put("id", project.getId().toString());
dataList.add(map);
}
}
}
response.setData(dataList);
response.setTotal(dataList.size());
} catch (Exception e) {
response.setStatus(-1);
response.setError(e.getMessage());
}
}
use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class ProdProcessService method getLanguageToPrinting.
public String getLanguageToPrinting(ProdProcess prodProcess) {
User user = AuthUtils.getUser();
String language = "en";
if (user != null && !Strings.isNullOrEmpty(user.getLanguage())) {
return user.getLanguage();
}
if (prodProcess == null) {
return language;
}
Company company = prodProcess.getCompany();
if (company != null && company.getPartner() != null) {
language = ReportSettings.getPrintingLocale(company.getPartner());
}
return language;
}
use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class SendMailQueueService method submitMailJob.
/**
* Submit a mail job to an executor which will send mails in a separate thread.
*
* @param mailBuilder
* @param message
*/
public void submitMailJob(MailBuilder mailBuilder, Message message) {
long messageId = message.getId();
log.debug("Submitting job to executor for message {}...", messageId);
User currentUser = AuthUtils.getUser();
executor.submit(() -> {
try {
final long startTime = System.currentTimeMillis();
boolean done = false;
PersistenceException persistenceException = null;
log.debug("Sending message {}...", messageId);
mailBuilder.send();
log.debug("Message {} sent.", messageId);
do {
try {
inTransaction(() -> {
final Message updateMessage = findMessage(messageId);
getEntityManager().lock(updateMessage, LockModeType.PESSIMISTIC_WRITE);
updateMessage.setSentByEmail(true);
updateMessage.setStatusSelect(MessageRepository.STATUS_SENT);
updateMessage.setSentDateT(LocalDateTime.now());
if (currentUser != null) {
updateMessage.setSenderUser(userRepository.find(currentUser.getId()));
}
messageRepository.save(updateMessage);
});
done = true;
} catch (PersistenceException e) {
persistenceException = e;
sleep();
}
} while (!done && System.currentTimeMillis() - startTime < ENTITY_FIND_TIMEOUT);
if (!done) {
throw persistenceException;
}
} catch (Exception e) {
log.debug("Exception when sending email", e);
TraceBackService.trace(e);
}
return true;
});
}
Aggregations