List of usage examples for javax.xml.datatype Duration negate
public abstract Duration negate();
From source file:Main.java
/** * Add one Duration to another, avoiding the runtime library bug that gives * incorrect results when using decimal seconds. * @param d1 The first duration/*from w w w . ja v a 2 s .c om*/ * @param d2 The second duration * @return The result of adding d1 to d2 */ public static Duration add(Duration d1, Duration d2) { boolean sign1 = d1.getSign() >= 0; boolean sign2 = d2.getSign() >= 0; if (sign1 && sign2) return addPositiveDurations(d1, d2); if (!sign1 && !sign2) return addPositiveDurations(d1.negate(), d2.negate()).negate(); if (sign1 && !sign2) return subtract(d1, d2.negate()); //if( ! sign1 && sign2 ) return subtract(d2, d1.negate()); }
From source file:Main.java
/** * Subtract one Duration from another, avoiding the runtime library bug that gives * incorrect results when using decimal seconds. * @param d1 The first duration/*from w ww .ja v a 2 s . c o m*/ * @param d2 The second duration * @return The result of subtracting d2 from d1 */ public static Duration subtract(Duration d1, Duration d2) { boolean sign1 = d1.getSign() >= 0; boolean sign2 = d2.getSign() >= 0; if (sign1 && sign2) { int comparison = d1.compare(d2); comparison = compare(d1, d2); if (comparison >= 0) return subtractSmallerPositiveDurationFromLargerPositiveDuration(d1, d2); else return subtractSmallerPositiveDurationFromLargerPositiveDuration(d2, d1).negate(); } if (!sign1 && !sign2) { d1 = d1.negate(); d2 = d2.negate(); int comparison = d1.compare(d2); comparison = compare(d1, d2); if (comparison < 0) return subtractSmallerPositiveDurationFromLargerPositiveDuration(d2, d1); else return subtractSmallerPositiveDurationFromLargerPositiveDuration(d1, d2).negate(); } if (sign1 && !sign2) return add(d1, d2.negate()); //if( ! sign1 && sign2 ) return add(d2, d1.negate()).negate(); }
From source file:com.evolveum.midpoint.repo.sql.SqlAuditServiceImpl.java
@Override public void cleanupAudit(CleanupPolicyType policy, OperationResult parentResult) { Validate.notNull(policy, "Cleanup policy must not be null."); Validate.notNull(parentResult, "Operation result must not be null."); final String operation = "deleting"; int attempt = 1; SqlPerformanceMonitor pm = getPerformanceMonitor(); long opHandle = pm.registerOperationStart("cleanupAudit"); if (policy.getMaxAge() == null) { return;/* w ww .j av a 2 s . c o m*/ } Duration duration = policy.getMaxAge(); if (duration.getSign() > 0) { duration = duration.negate(); } Date minValue = new Date(); duration.addTo(minValue); // factored out because it produces INFO-level message Dialect dialect = Dialect.getDialect(getSessionFactoryBean().getHibernateProperties()); if (!dialect.supportsTemporaryTables()) { LOGGER.error("Dialect {} doesn't support temporary tables, couldn't cleanup audit logs.", dialect); throw new SystemException( "Dialect " + dialect + " doesn't support temporary tables, couldn't cleanup audit logs."); } long start = System.currentTimeMillis(); boolean first = true; Holder<Integer> totalCountHolder = new Holder<>(0); try { while (true) { try { LOGGER.info("{} audit cleanup, deleting up to {} (duration '{}'), batch size {}{}.", first ? "Starting" : "Restarting", minValue, duration, CLEANUP_AUDIT_BATCH_SIZE, first ? "" : ", up to now deleted " + totalCountHolder.getValue() + " entries"); first = false; int count; do { // the following method may restart due to concurrency (or any other) problem - in any iteration count = cleanupAuditAttempt(minValue, duration, totalCountHolder, dialect, parentResult); } while (count > 0); return; } catch (RuntimeException ex) { attempt = logOperationAttempt(null, operation, attempt, ex, parentResult); pm.registerOperationNewTrial(opHandle, attempt); } } } finally { pm.registerOperationFinish(opHandle, attempt); LOGGER.info("Audit cleanup finished; deleted {} entries in {} seconds.", totalCountHolder.getValue(), (System.currentTimeMillis() - start) / 1000L); } }
From source file:com.evolveum.midpoint.test.DummyAuditService.java
@Override public void cleanupAudit(CleanupPolicyType policy, OperationResult parentResult) { Validate.notNull(policy, "Cleanup policy must not be null."); Validate.notNull(parentResult, "Operation result must not be null."); if (policy.getMaxAge() == null) { return;//from www .ja va 2 s .c o m } Duration duration = policy.getMaxAge(); if (duration.getSign() > 0) { duration = duration.negate(); } long minValue = duration.getTimeInMillis(new Date()); Iterator<AuditEventRecord> iterator = records.iterator(); while (iterator.hasNext()) { AuditEventRecord record = iterator.next(); Long timestamp = record.getTimestamp(); if (timestamp == null) { continue; } if (timestamp < minValue) { iterator.remove(); } } }
From source file:com.evolveum.midpoint.report.impl.ReportManagerImpl.java
@Override public void cleanupReports(CleanupPolicyType cleanupPolicy, OperationResult parentResult) { OperationResult result = parentResult.createSubresult(CLEANUP_REPORT_OUTPUTS); if (cleanupPolicy.getMaxAge() == null) { return;/*www. j av a 2s . co m*/ } Duration duration = cleanupPolicy.getMaxAge(); if (duration.getSign() > 0) { duration = duration.negate(); } Date deleteReportOutputsTo = new Date(); duration.addTo(deleteReportOutputsTo); LOGGER.info("Starting cleanup for report outputs deleting up to {} (duration '{}').", new Object[] { deleteReportOutputsTo, duration }); XMLGregorianCalendar timeXml = XmlTypeConverter.createXMLGregorianCalendar(deleteReportOutputsTo.getTime()); List<PrismObject<ReportOutputType>> obsoleteReportOutputs = new ArrayList<PrismObject<ReportOutputType>>(); try { ObjectQuery obsoleteReportOutputsQuery = ObjectQuery.createObjectQuery(LessFilter.createLess( new ItemPath(ReportOutputType.F_METADATA, MetadataType.F_CREATE_TIMESTAMP), ReportOutputType.class, prismContext, timeXml, true)); obsoleteReportOutputs = modelService.searchObjects(ReportOutputType.class, obsoleteReportOutputsQuery, null, null, result); } catch (Exception e) { throw new SystemException("Couldn't get the list of obsolete report outputs: " + e.getMessage(), e); } LOGGER.debug("Found {} report output(s) to be cleaned up", obsoleteReportOutputs.size()); boolean interrupted = false; int deleted = 0; int problems = 0; for (PrismObject<ReportOutputType> reportOutputPrism : obsoleteReportOutputs) { ReportOutputType reportOutput = reportOutputPrism.asObjectable(); LOGGER.trace("Removing report output {} along with {} file.", reportOutput.getName().getOrig(), reportOutput.getFilePath()); boolean problem = false; try { deleteReportOutput(reportOutput, result); } catch (Exception e) { LoggingUtils.logException(LOGGER, "Couldn't delete obsolete report output {} due to a exception", e, reportOutput); problem = true; } if (problem) { problems++; } else { deleted++; } } result.computeStatusIfUnknown(); LOGGER.info("Report cleanup procedure " + (interrupted ? "was interrupted" : "finished") + ". Successfully deleted {} report outputs; there were problems with deleting {} report ouptuts.", deleted, problems); String suffix = interrupted ? " Interrupted." : ""; if (problems == 0) { parentResult.createSubresult(CLEANUP_REPORT_OUTPUTS + ".statistics").recordStatus( OperationResultStatus.SUCCESS, "Successfully deleted " + deleted + " report output(s)." + suffix); } else { parentResult.createSubresult(CLEANUP_REPORT_OUTPUTS + ".statistics") .recordPartialError("Successfully deleted " + deleted + " report output(s), " + "there was problems with deleting " + problems + " report outputs."); } }
From source file:com.evolveum.midpoint.model.impl.sync.FocusValidityScannerTaskHandler.java
@Override protected ObjectQuery createQuery(AbstractScannerResultHandler<FocusType> handler, TaskRunResult runResult, Task coordinatorTask, OperationResult opResult) throws SchemaException { initProcessedOids(coordinatorTask);//from www. ja v a 2s. co m TimeValidityPolicyConstraintType validityConstraintType = getValidityPolicyConstraint(coordinatorTask); Duration activateOn = getActivateOn(validityConstraintType); Integer partition = getPartition(coordinatorTask); ObjectQuery query = new ObjectQuery(); ObjectFilter filter; XMLGregorianCalendar lastScanTimestamp = handler.getLastScanTimestamp(); XMLGregorianCalendar thisScanTimestamp = handler.getThisScanTimestamp(); if (activateOn != null) { ItemPathType itemPathType = validityConstraintType.getItem(); ItemPath path = itemPathType.getItemPath(); if (path == null) { throw new SchemaException("No path defined in the validity constraint."); } thisScanTimestamp.add(activateOn.negate()); if (lastScanTimestamp != null) { lastScanTimestamp.add(activateOn.negate()); } filter = createFilterFor(getType(coordinatorTask), path, lastScanTimestamp, thisScanTimestamp); } else { filter = createBasicFilter(lastScanTimestamp, thisScanTimestamp, partition); } query.setFilter(filter); return query; }
From source file:com.evolveum.midpoint.task.quartzimpl.TaskManagerQuartzImpl.java
@Override public void cleanupTasks(CleanupPolicyType policy, Task executionTask, OperationResult parentResult) throws SchemaException { OperationResult result = parentResult.createSubresult(CLEANUP_TASKS); if (policy.getMaxAge() == null) { return;//w w w . j ava2 s . c o m } Duration duration = policy.getMaxAge(); if (duration.getSign() > 0) { duration = duration.negate(); } Date deleteTasksClosedUpTo = new Date(); duration.addTo(deleteTasksClosedUpTo); LOGGER.info("Starting cleanup for closed tasks deleting up to {} (duration '{}').", new Object[] { deleteTasksClosedUpTo, duration }); XMLGregorianCalendar timeXml = XmlTypeConverter.createXMLGregorianCalendar(deleteTasksClosedUpTo.getTime()); List<PrismObject<TaskType>> obsoleteTasks; try { ObjectQuery obsoleteTasksQuery = ObjectQuery.createObjectQuery(AndFilter.createAnd( LessFilter.createLess(TaskType.F_COMPLETION_TIMESTAMP, TaskType.class, getPrismContext(), timeXml, true), EqualFilter.createEqual(TaskType.F_PARENT, TaskType.class, getPrismContext(), null))); obsoleteTasks = repositoryService.searchObjects(TaskType.class, obsoleteTasksQuery, null, result); } catch (SchemaException e) { throw new SchemaException("Couldn't get the list of obsolete tasks: " + e.getMessage(), e); } LOGGER.debug("Found {} task tree(s) to be cleaned up", obsoleteTasks.size()); boolean interrupted = false; int deleted = 0; int problems = 0; int bigProblems = 0; for (PrismObject<TaskType> rootTaskPrism : obsoleteTasks) { if (!executionTask.canRun()) { result.recordPartialError("Interrupted"); LOGGER.warn("Task cleanup was interrupted."); interrupted = true; break; } // get whole tree Task rootTask = createTaskInstance(rootTaskPrism, result); List<Task> taskTreeMembers = rootTask.listSubtasksDeeply(result); taskTreeMembers.add(rootTask); LOGGER.trace("Removing task {} along with its {} children.", rootTask, taskTreeMembers.size() - 1); boolean problem = false; for (Task task : taskTreeMembers) { try { deleteTask(task.getOid(), result); } catch (SchemaException e) { LoggingUtils.logException(LOGGER, "Couldn't delete obsolete task {} due to schema exception", e, task); problem = true; } catch (ObjectNotFoundException e) { LoggingUtils.logException(LOGGER, "Couldn't delete obsolete task {} due to object not found exception", e, task); problem = true; } catch (RuntimeException e) { LoggingUtils.logException(LOGGER, "Couldn't delete obsolete task {} due to a runtime exception", e, task); problem = true; } if (problem) { problems++; if (!task.getTaskIdentifier().equals(rootTask.getTaskIdentifier())) { bigProblems++; } } else { deleted++; } } } result.computeStatusIfUnknown(); LOGGER.info( "Task cleanup procedure " + (interrupted ? "was interrupted" : "finished") + ". Successfully deleted {} tasks; there were problems with deleting {} tasks.", deleted, problems); if (bigProblems > 0) { LOGGER.error( "{} subtask(s) couldn't be deleted. Inspect that manually, otherwise they might reside in repo forever.", bigProblems); } String suffix = interrupted ? " Interrupted." : ""; if (problems == 0) { parentResult.createSubresult(CLEANUP_TASKS + ".statistics").recordStatus(OperationResultStatus.SUCCESS, "Successfully deleted " + deleted + " task(s)." + suffix); } else { parentResult.createSubresult(CLEANUP_TASKS + ".statistics") .recordPartialError("Successfully deleted " + deleted + " task(s), " + "there was problems with deleting " + problems + " tasks." + suffix + (bigProblems > 0 ? (" " + bigProblems + " subtask(s) couldn't be deleted, please see the log.") : "")); } }