use of com.haulmont.cuba.security.app.Authenticated in project cuba by cuba-platform.
the class PersistenceManager method jpqlLoadList.
@Authenticated
@Override
public String jpqlLoadList(String queryString) {
try {
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
Query query = em.createQuery(queryString);
QueryParser parser = QueryTransformerFactory.createParser(queryString);
Set<String> paramNames = parser.getParamNames();
for (String paramName : paramNames) {
security.setQueryParam(query, paramName);
}
List resultList = query.getResultList();
tx.commit();
StrBuilder sb = new StrBuilder();
for (Object element : resultList) {
if (element instanceof Object[]) {
sb.appendWithSeparators((Object[]) element, " | ");
} else {
sb.append(element);
}
sb.append("\n");
}
return sb.toString();
} finally {
tx.end();
}
} catch (Throwable e) {
log.error("jpqlLoadList error", e);
return ExceptionUtils.getStackTrace(e);
}
}
use of com.haulmont.cuba.security.app.Authenticated in project cuba by cuba-platform.
the class Emailer method sendTestEmail.
@Authenticated
@Override
public String sendTestEmail(String addresses) {
try {
String att = "<html><body><h1>Test attachment</h1></body></html>";
EmailAttachment emailAtt = EmailAttachment.createTextAttachment(att, StandardCharsets.UTF_8.name(), "test attachment.html");
emailer.sendEmail(addresses, "Test email", "<html><body><h1>Test email</h1></body></html>", emailAtt);
return "Email to '" + addresses + "' sent successfully";
} catch (Exception e) {
return ExceptionUtils.getStackTrace(e);
}
}
use of com.haulmont.cuba.security.app.Authenticated in project cuba by cuba-platform.
the class PersistenceManager method refreshStatistics.
@Authenticated
@Override
public String refreshStatistics(String entityName) {
if (StringUtils.isBlank(entityName))
return "Pass an entity name (MetaClass name, e.g. sec$User) or 'all' to refresh statistics for all entities.\n" + "Be careful, it can take very long time.";
try {
log.info("Refreshing statistics for " + entityName);
Consumer<MetaClass> refreshStatisticsForEntity = mc -> {
MetaClass originalMetaClass = metadata.getExtendedEntities().getOriginalOrThisMetaClass(mc);
Class javaClass = originalMetaClass.getJavaClass();
Table annotation = (Table) javaClass.getAnnotation(Table.class);
if (annotation != null) {
persistenceManager.refreshStatisticsForEntity(originalMetaClass.getName());
}
};
if ("all".equals(entityName)) {
for (MetaClass metaClass : metadata.getSession().getClasses()) {
refreshStatisticsForEntity.accept(metaClass);
}
} else {
MetaClass metaClass = metadata.getSession().getClass(entityName);
if (metaClass == null)
return "MetaClass not found: " + entityName;
refreshStatisticsForEntity.accept(metaClass);
}
return "Done";
} catch (Exception e) {
log.error("refreshStatistics error", e);
return ExceptionUtils.getStackTrace(e);
}
}
use of com.haulmont.cuba.security.app.Authenticated in project cuba by cuba-platform.
the class PersistenceManager method enterStatistics.
@Authenticated
@Override
public synchronized String enterStatistics(String name, Long instanceCount, Integer fetchUI, Integer maxFetchUI, Integer lazyCollectionThreshold, Integer lookupScreenThreshold) {
if (StringUtils.isBlank(name))
return "Entity name is required";
try {
EntityStatistics es = persistenceManager.enterStatistics(name, instanceCount, fetchUI, maxFetchUI, lazyCollectionThreshold, lookupScreenThreshold);
StringBuilder sb = new StringBuilder("Statistics for ").append(name).append(" changed:\n");
sb.append("instanceCount=").append(es.getInstanceCount()).append("\n");
sb.append("fetchUI=").append(es.getFetchUI()).append("\n");
sb.append("maxFetchUI=").append(es.getMaxFetchUI()).append("\n");
sb.append("lazyCollectionThreshold=").append(es.getLazyCollectionThreshold()).append("\n");
sb.append("lookupScreenThreshold=").append(es.getLookupScreenThreshold()).append("\n");
return sb.toString();
} catch (Exception e) {
log.error("enterStatistics error", e);
return ExceptionUtils.getStackTrace(e);
}
}
use of com.haulmont.cuba.security.app.Authenticated in project cuba by cuba-platform.
the class Scheduling method removeExecutionHistory.
@Authenticated
@Override
public String removeExecutionHistory(String age, String maxPeriod) {
List<UUID> list;
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
String jpql = "select e.id from sys$ScheduledExecution e where e.startTime < ?1";
if (maxPeriod != null) {
jpql += " and e.task.period <= ?2";
}
jpql += " order by e.startTime";
Query query = em.createQuery(jpql);
Date startDate = DateUtils.addHours(timeSource.currentTimestamp(), -Integer.parseInt(age));
query.setParameter(1, startDate);
if (maxPeriod != null) {
query.setParameter(2, Integer.parseInt(maxPeriod) * 3600);
}
list = query.getResultList();
tx.commit();
} finally {
tx.end();
}
for (int i = 0; i < list.size(); i += 100) {
final List<UUID> subList = list.subList(i, Math.min(i + 100, list.size()));
persistence.createTransaction().execute(new Transaction.Runnable() {
@Override
public void run(EntityManager em) {
Query query = em.createQuery("delete from sys$ScheduledExecution e where e.id in ?1");
query.setParameter(1, subList);
query.executeUpdate();
}
});
}
return "Deleted " + list.size();
}
Aggregations