-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #484: Consolidate ZenId verification ID
Add RequiredDocumentTypesGuard
- Loading branch information
Showing
2 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...m/wultra/app/onboardingserver/statemachine/guard/document/RequiredDocumentTypesGuard.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* PowerAuth Enrollment Server | ||
* Copyright (C) 2022 Wultra s.r.o. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.wultra.app.onboardingserver.statemachine.guard.document; | ||
|
||
import com.wultra.app.enrollmentserver.model.enumeration.DocumentStatus; | ||
import com.wultra.app.onboardingserver.common.database.entity.IdentityVerificationEntity; | ||
import com.wultra.app.onboardingserver.statemachine.consts.ExtendedStateVariable; | ||
import com.wultra.app.onboardingserver.statemachine.enums.OnboardingEvent; | ||
import com.wultra.app.onboardingserver.statemachine.enums.OnboardingState; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.statemachine.StateContext; | ||
import org.springframework.statemachine.guard.Guard; | ||
import org.springframework.stereotype.Component; | ||
|
||
import static java.util.stream.Collectors.toList; | ||
|
||
/** | ||
* Wrapper of {@link RequiredDocumentTypesCheck} to spring state machine guard. | ||
* | ||
* @author Lubos Racansky, lubos.racansky@wultra.com | ||
*/ | ||
@Component | ||
public class RequiredDocumentTypesGuard implements Guard<OnboardingState, OnboardingEvent> { | ||
|
||
private final RequiredDocumentTypesCheck requiredDocumentTypesCheck; | ||
|
||
@Autowired | ||
public RequiredDocumentTypesGuard(final RequiredDocumentTypesCheck requiredDocumentTypesCheck) { | ||
this.requiredDocumentTypesCheck = requiredDocumentTypesCheck; | ||
} | ||
|
||
@Override | ||
public boolean evaluate(StateContext<OnboardingState, OnboardingEvent> context) { | ||
final IdentityVerificationEntity identityVerification = context.getExtendedState().get(ExtendedStateVariable.IDENTITY_VERIFICATION, IdentityVerificationEntity.class); | ||
final var acceptedDocumentVerifications = identityVerification.getDocumentVerifications().stream() | ||
.filter(it -> it.getStatus() == DocumentStatus.ACCEPTED) | ||
.collect(toList()); | ||
return requiredDocumentTypesCheck.evaluate(acceptedDocumentVerifications, identityVerification.getId()); | ||
} | ||
} |