Skip to content

Commit

Permalink
Fix lifecycle management
Browse files Browse the repository at this point in the history
  • Loading branch information
enricovianello committed Dec 20, 2024
1 parent 8f068aa commit 284fbeb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.List;
import java.util.Optional;

import org.joda.time.DateTimeComparator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Profile;
Expand Down Expand Up @@ -128,17 +129,16 @@ public void handleAccount(String cernPersonId, String experiment, IamAccount a)
return;
}

syncAccountEndTime(a, ep.get().getEndDate());
setCernStatusLabel(a, CernStatus.VO_MEMBER, format(SYNCHRONIZED_MESSAGE));

if (CernHrLifecycleUtils.isActiveMembership(a.getEndTime()) && !a.isActive()
if (CernHrLifecycleUtils.isActiveMembership(ep.get().getEndDate()) && !a.isActive()
&& accountWasSuspendedByIamLifecycleJob(a)) {
restoreAccount(a);
}
syncAccountEndTime(a, ep.get().getEndDate());
setCernStatusLabel(a, CernStatus.VO_MEMBER, format(SYNCHRONIZED_MESSAGE));
}

private void expireIfActiveAndMember(IamAccount a) {
if (CernHrLifecycleUtils.isActiveMembership(a.getEndTime()) && a.isActive()) {
if (DateTimeComparator.getInstance().compare(a.getEndTime(), new Date()) > 0 && a.isActive()) {
expireAccount(a);
}
}
Expand Down Expand Up @@ -238,8 +238,6 @@ private void setCernStatusLabel(IamAccount a, CernStatus status, String message)

private void restoreAccount(IamAccount a) {
accountService.restoreAccount(a);
IamLabel statusLabel = CernHrLifecycleUtils.buildLifecycleStatusLabel();
accountService.deleteLabel(a, statusLabel);
}

private void syncAccountEndTime(IamAccount a, Date endDate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.isNullOrEmpty;
import static it.infn.mw.iam.core.lifecycle.ExpiredAccountsHandler.LIFECYCLE_STATUS_LABEL;
import static java.lang.String.format;
import static java.util.Objects.isNull;

Expand Down Expand Up @@ -460,6 +461,7 @@ public IamAccount setAccountEndTime(IamAccount account, Date endTime) {
Date previousEndTime = account.getEndTime();
if (ObjectUtils.notEqual(previousEndTime, endTime)) {
account.setEndTime(endTime);
account.removeLabelByName(LIFECYCLE_STATUS_LABEL);
account.touch();
accountRepo.save(account);
eventPublisher.publishEvent(new AccountEndTimeUpdatedEvent(this, account, previousEndTime,
Expand Down

0 comments on commit 284fbeb

Please sign in to comment.