package gw.job.uw uses java.util.Date uses java.lang.UnsupportedOperationException uses gw.api.extension.ExtensionInterfaces /** * The part of a UWIssue related to its approval, if any. * * This is a shim class, intended to ease the transition from separate issue and approval * entities to combined. * This code mostly implements the same interface that the old approval entity presented, * by mapping calls to the corresponding part of the issue. */ class UWIssueApproval { /* * N.B. it's important not to have any other state in UWIssueApproval other than its UWIssue. * This allows as many UWIssueApproval's as desired be instantiated over the same UWIssue without harm. */ var _issue : UWIssue as readonly Issue construct(issueArg : UWIssue) { var periodEditEffectiveDate = issueArg.PolicyPeriod.EditEffectiveDate _issue = issueArg if (periodEditEffectiveDate > issueArg.EffectiveDate and periodEditEffectiveDate < issueArg.ExpirationDate) { _issue = issueArg.getSlice(periodEditEffectiveDate) } if (not Issue.HasApprovalOrRejection) { initializeNewApproval() } } property get ApprovingUser() : User { return Issue.ApprovingUser } property set ApprovingUser(user : User) { doForThisAndFutureIssueVersions( \ i -> {i.ApprovingUser = user}) } property get NonCurrencyReferenceValue() : String { return ExtensionInterfaces.IUWIssueExtensions.getNonCurrencyReferenceValue(Issue) } property set NonCurrencyReferenceValue(value : String) { doForThisAndFutureIssueVersions( \ i -> {ExtensionInterfaces.IUWIssueExtensions.setNonCurrencyReferenceValue(i, value)}) } property get ReferenceValue() : String { return Issue.ApprovalValue } property set ReferenceValue(value : String) { doForThisAndFutureIssueVersions( \ i -> {i.ApprovalValue = value}) } property get ReferenceValueCurrency() : Currency { return ExtensionInterfaces.IUWIssueExtensions.getApprovalValueCurrency(Issue) } property set ReferenceValueCurrency(value : Currency) { throw new UnsupportedOperationException("Not allowed to change the currency on UWIssueApprovals at this time") } property get AutomaticApprovalCause() : String { return Issue.AutomaticApprovalCause } property set AutomaticApprovalCause(cause : String) { doForThisAndFutureIssueVersions( \i -> {i.AutomaticApprovalCause = cause}) } property get EditBeforeBind() : boolean { return Issue.CanEditApprovalBeforeBind } property set EditBeforeBind(canEditBeforeBind : boolean) { doForThisAndFutureIssueVersions( \ i -> {i.CanEditApprovalBeforeBind = canEditBeforeBind}) } property get BlockingPoint() : UWIssueBlockingPoint { return Issue.ApprovalBlockingPoint } property set BlockingPoint(bp : UWIssueBlockingPoint){ doForThisAndFutureIssueVersions( \ i -> {i.ApprovalBlockingPoint = bp}) } property get DurationType() : UWApprovalDurationType { return Issue.ApprovalDurationType } property set DurationType(_type : UWApprovalDurationType) { doForThisAndFutureIssueVersions( \ i -> {i.ApprovalDurationType = _type}) } property get ApprovalInvalidFrom() : Date { return Issue.ApprovalInvalidFrom } property set ApprovalInvalidFrom(_date : Date) { doForThisAndFutureIssueVersions( \ i -> {i.ApprovalInvalidFrom = _date}) } /** * Should be called exactly once when the approval has the values it will have * once committed. */ function createApprovalHistoryFromCurrentValues() : UWIssueApproval { ExtensionInterfaces.IUWIssueExtensions.createApprovalHistoryFromCurrentValues(Issue) return this } /////////////////////////////////////////////////////////////////////////////////// property get Bundle() : gw.pl.persistence.core.Bundle { return Issue.Bundle } property get Branch() : PolicyPeriod { return Issue.Branch } property get SliceDate() : Date { return Issue.SliceDate } property get BasedOn() : UWIssueApproval { var basedOnIssue = Issue.BasedOn return basedOnIssue == null ? null : new UWIssueApproval(basedOnIssue) } function removeFutureApprovalsOrRejections() { doForThisAndFutureIssueVersions( \ i -> {i.HasApprovalOrRejection = false}) } private function initializeNewApproval() { doForThisAndFutureIssueVersions( \ i -> { i.HasApprovalOrRejection = true i.CanEditApprovalBeforeBind = true }) } override public function hashCode() : int { return Issue.hashCode() } override public function equals(o : Object) : boolean { if (this === o) { return true } return o typeis UWIssueApproval and (Issue == o.Issue) } private function doForThisAndFutureIssueVersions(action(i : UWIssue)) { var issueSliceDate = this.Issue.SliceDate for (i in Issue.VersionList.AllVersions) { if (issueSliceDate <= i.EffectiveDate) { action(i) } else if (issueSliceDate < i.ExpirationDate) { action(i.getSlice(issueSliceDate)) } } } }