use of java.util.Objects in project gerrit by GerritCodeReview.
the class ReviewersUtil method loadAccounts.
private List<SuggestedReviewerInfo> loadAccounts(List<Account.Id> accountIds) throws OrmException {
try (Timer0.Context ctx = metrics.loadAccountsLatency.start()) {
List<SuggestedReviewerInfo> reviewer = accountIds.stream().map(accountLoader::get).filter(Objects::nonNull).map(a -> {
SuggestedReviewerInfo info = new SuggestedReviewerInfo();
info.account = a;
info.count = 1;
return info;
}).collect(toList());
accountLoader.fill();
return reviewer;
}
}
use of java.util.Objects in project midpoint by Evolveum.
the class AccCertCaseOperationsHelper method getDeltasToCreateCases.
<F extends FocusType> List<ItemDelta<?, ?>> getDeltasToCreateCases(final AccessCertificationCampaignType campaign, AccessCertificationStageType stage, final CertificationHandler handler, final Task task, final OperationResult result) throws SchemaException, ObjectNotFoundException {
final List<ItemDelta<?, ?>> rv = new ArrayList<>();
final String campaignShortName = toShortString(campaign);
final AccessCertificationScopeType scope = campaign.getScopeDefinition();
LOGGER.trace("Creating cases for scope {} in campaign {}", scope, campaignShortName);
if (scope != null && !(scope instanceof AccessCertificationObjectBasedScopeType)) {
throw new IllegalStateException("Unsupported access certification scope type: " + scope.getClass() + " for campaign " + campaignShortName);
}
final AccessCertificationObjectBasedScopeType objectBasedScope = (AccessCertificationObjectBasedScopeType) scope;
final List<AccessCertificationCaseType> existingCases = queryHelper.searchCases(campaign.getOid(), null, null, result);
if (!existingCases.isEmpty()) {
throw new IllegalStateException("Unexpected " + existingCases.size() + " certification case(s) in campaign object " + campaignShortName + ". At this time there should be none.");
}
// create a query to find target objects from which certification cases will be created
final ObjectQuery query = new ObjectQuery();
final QName scopeDeclaredObjectType;
if (objectBasedScope != null) {
scopeDeclaredObjectType = objectBasedScope.getObjectType();
} else {
scopeDeclaredObjectType = null;
}
final QName objectType;
if (scopeDeclaredObjectType != null) {
objectType = scopeDeclaredObjectType;
} else {
objectType = handler.getDefaultObjectType();
}
if (objectType == null) {
throw new IllegalStateException("Unspecified object type (and no default one provided) for campaign " + campaignShortName);
}
@SuppressWarnings({ "unchecked", "raw" }) final Class<F> objectClass = (Class<F>) prismContext.getSchemaRegistry().getCompileTimeClassForObjectType(objectType);
if (objectClass == null) {
throw new IllegalStateException("Object class not found for object type " + objectType + " in campaign " + campaignShortName);
}
final SearchFilterType searchFilter = objectBasedScope != null ? objectBasedScope.getSearchFilter() : null;
if (searchFilter != null) {
ObjectFilter filter = QueryConvertor.parseFilter(searchFilter, objectClass, prismContext);
query.setFilter(filter);
}
final List<AccessCertificationCaseType> caseList = new ArrayList<>();
// create certification cases by executing the query and caseExpression on its results
// here the subclasses of this class come into play
ResultHandler<F> resultHandler = (object, parentResult) -> {
try {
caseList.addAll(handler.createCasesForObject(object, campaign, task, parentResult));
} catch (ExpressionEvaluationException | ObjectNotFoundException | SchemaException e) {
// TODO process the exception more intelligently
throw new SystemException("Cannot create certification case for object " + toShortString(object.asObjectable()) + ": " + e.getMessage(), e);
}
return true;
};
repositoryService.searchObjectsIterative(objectClass, query, resultHandler, null, false, result);
AccessCertificationReviewerSpecificationType reviewerSpec = reviewersHelper.findReviewersSpecification(campaign, 1, task, result);
ContainerDelta<AccessCertificationCaseType> caseDelta = ContainerDelta.createDelta(F_CASE, AccessCertificationCampaignType.class, prismContext);
for (AccessCertificationCaseType _case : caseList) {
_case.setStageNumber(1);
_case.setCurrentStageCreateTimestamp(stage.getStartTimestamp());
_case.setCurrentStageDeadline(stage.getDeadline());
List<ObjectReferenceType> reviewers = reviewersHelper.getReviewersForCase(_case, campaign, reviewerSpec, task, result);
_case.getWorkItem().addAll(createWorkItems(reviewers, 1));
String currentStageOutcome = OutcomeUtils.toUri(computationHelper.computeOutcomeForStage(_case, campaign, 1));
_case.setCurrentStageOutcome(currentStageOutcome);
_case.setOutcome(OutcomeUtils.toUri(computationHelper.computeOverallOutcome(_case, campaign, currentStageOutcome)));
@SuppressWarnings({ "raw", "unchecked" }) PrismContainerValue<AccessCertificationCaseType> caseCVal = _case.asPrismContainerValue();
caseDelta.addValueToAdd(caseCVal);
LOGGER.trace("Adding certification case:\n{}", caseCVal.debugDumpLazily());
}
rv.add(caseDelta);
LOGGER.trace("Created {} deltas to create {} cases for campaign {}", rv.size(), caseList.size(), campaignShortName);
return rv;
}
use of java.util.Objects in project indy by Commonjava.
the class ScheduleManager method setSnapshotTimeouts.
public synchronized void setSnapshotTimeouts(final StoreKey key, final String path) throws IndySchedulerException {
if (!schedulerConfig.isEnabled()) {
logger.debug("Scheduler disabled.");
return;
}
HostedRepository deploy = null;
try {
final ArtifactStore store = dataManager.getArtifactStore(key);
if (store == null) {
return;
}
if (store instanceof HostedRepository) {
deploy = (HostedRepository) store;
} else if (store instanceof Group) {
final Group group = (Group) store;
deploy = findDeployPoint(group);
}
} catch (final IndyDataException e) {
logger.error(String.format("Failed to retrieve deploy point for: %s. Reason: %s", key, e.getMessage()), e);
}
if (deploy == null) {
return;
}
final ContentAdvisor advisor = StreamSupport.stream(Spliterators.spliteratorUnknownSize(contentAdvisor.iterator(), Spliterator.ORDERED), false).filter(Objects::nonNull).findFirst().orElse(null);
final ContentQuality quality = advisor == null ? null : advisor.getContentQuality(path);
if (quality == null) {
return;
}
if (ContentQuality.SNAPSHOT == quality && deploy.getSnapshotTimeoutSeconds() > 0) {
final int timeout = deploy.getSnapshotTimeoutSeconds();
// // logger.info( "[SNAPSHOT TIMEOUT SET] {}/{}; {}", deploy.getKey(), path, new Date( timeout ) );
// cancel( new StoreKeyMatcher( key, CONTENT_JOB_TYPE ), path );
scheduleContentExpiration(key, path, timeout);
}
}
use of java.util.Objects in project intellij-plugins by StepicOrg.
the class StudySerializationUtils method convertToFourthVersion.
public static Element convertToFourthVersion(Element state) throws StudyUnrecognizedFormatException {
Element stepManager = getStepManager(state);
Element courseNode = getCourseNode(stepManager);
List<Element> sectionNodes = getSectionNodes(stepManager);
if (sectionNodes != null) {
sectionNodes.stream().map(sectionNode -> getListFieldWithNameOrNull(sectionNode, LESSON_NODES, LESSON_NODE_CLASS)).filter(Objects::nonNull).forEach(lessonNodes -> lessonNodes.forEach(lessonNode -> {
Element data = getFieldWithNameOrNull(lessonNode, DATA);
Element dataClassTag;
if (data == null) {
return;
}
dataClassTag = data.getChild(LESSON_CLASS);
Element dataCloned;
if (dataClassTag == null) {
dataClassTag = createFieldWithClass(lessonNode, LESSON, LESSON_CLASS);
dataCloned = dataClassTag.getParentElement();
} else {
dataCloned = data.clone();
dataCloned.getAttribute(NAME).setValue(LESSON);
}
dataClassTag.removeContent();
dataClassTag.addContent(dataCloned);
Element unit = getFieldWithNameOrNull(lessonNode, UNIT);
if (unit != null) {
Element unitCloned = unit.clone();
dataClassTag.addContent(unitCloned);
removeChild(lessonNode, unit);
}
dataClassTag.setName(COMPOUND_UNIT_LESSON_CLASS);
List<Element> stepNodes = getListFieldWithNameOrNull(lessonNode, STEP_NODES, STEP_NODE_CLASS);
if (stepNodes == null) {
return;
}
stepNodes.forEach(stepNode -> removeOption(stepNode, LIMITS));
silentRenameField(lessonNode, STEP_NODES, CHILDREN);
}));
sectionNodes.forEach(sectionNode -> silentRenameField(sectionNode, LESSON_NODES, CHILDREN));
silentRenameField(courseNode, SECTIONS_NODES, CHILDREN);
}
List<Element> elements = stepManager.getChildren();
Element root = renameField(stepManager, COURSE_NODE, ROOT);
root.setAttribute("class", COURSE_NODE_CLASS);
convertToXStreamStyle(elements);
return state;
}
use of java.util.Objects in project jgnash by ccavanaugh.
the class Engine method emptyTrash.
/**
* Empty the trash if any objects are older than the defined time.
*/
private void emptyTrash() {
if (backGroundCounter.incrementAndGet() == 1) {
messageBus.fireEvent(new Message(MessageChannel.SYSTEM, ChannelEvent.BACKGROUND_PROCESS_STARTED, Engine.this));
}
dataLock.writeLock().lock();
try {
logger.info("Checking for trash");
final List<TrashObject> trash = getTrashDAO().getTrashObjects();
/* always sort by the timestamp of the trash object to prevent
* foreign key removal exceptions when multiple related accounts
* or objects are removed */
Collections.sort(trash);
if (trash.isEmpty()) {
logger.info("No trash was found");
}
trash.stream().filter(o -> ChronoUnit.MILLIS.between(o.getDate(), LocalDateTime.now()) >= MAXIMUM_TRASH_AGE).forEach(o -> getTrashDAO().remove(o));
} finally {
dataLock.writeLock().unlock();
if (backGroundCounter.decrementAndGet() == 0) {
messageBus.fireEvent(new Message(MessageChannel.SYSTEM, ChannelEvent.BACKGROUND_PROCESS_STOPPED, Engine.this));
}
}
}
Aggregations