@Test public void isSavedToConfiguration() throws Exception { KeyInfo savedKey = new TokenTestUtils.KeyInfoBuilder().build(); KeyInfo unsavedKey = new TokenTestUtils.KeyInfoBuilder().build(); savedKey.getCerts().clear(); savedKey.getCertRequests().clear(); savedKey.getCertRequests().add(KeyConverterTest.createTestCsr()); unsavedKey.getCerts().clear(); unsavedKey.getCertRequests().clear(); TokenInfo tokenInfo = new TokenTestUtils.TokenInfoBuilder().build(); tokenInfo.getKeyInfo().clear(); assertEquals(false, tokenConverter.convert(tokenInfo).getSavedToConfiguration()); tokenInfo.getKeyInfo().clear(); tokenInfo.getKeyInfo().add(unsavedKey); assertEquals(false, tokenConverter.convert(tokenInfo).getSavedToConfiguration()); tokenInfo.getKeyInfo().clear(); tokenInfo.getKeyInfo().add(savedKey); assertEquals(true, tokenConverter.convert(tokenInfo).getSavedToConfiguration()); tokenInfo.getKeyInfo().clear(); tokenInfo.getKeyInfo().add(unsavedKey); tokenInfo.getKeyInfo().add(savedKey); tokenInfo.getKeyInfo().add(unsavedKey); assertEquals(true, tokenConverter.convert(tokenInfo).getSavedToConfiguration()); }
public Token convert(TokenInfo tokenInfo) { Token token = new Token(); token.setId(tokenInfo.getId()); token.setName(tokenInfo.getFriendlyName()); if (TokenInfo.SOFTWARE_MODULE_TYPE.equals(tokenInfo.getType())) { token.setType(TokenType.SOFTWARE); } else { token.setType(TokenType.HARDWARE); } token.setKeys(keyConverter.convert(tokenInfo.getKeyInfo(), tokenInfo)); Optional<TokenStatus> status = TokenStatusMapping.map(tokenInfo.getStatus()); token.setStatus(status.orElse(null)); token.setLoggedIn(tokenInfo.isActive()); token.setAvailable(tokenInfo.isAvailable()); token.setSavedToConfiguration(tokenInfo.isSavedToConfiguration()); token.setReadOnly(tokenInfo.isReadOnly()); token.setSerialNumber(tokenInfo.getSerialNumber()); token.setTokenInfos(new ArrayList<>()); for (String key: tokenInfo.getTokenInfo().keySet()) { KeyValuePair keyValuePair = new KeyValuePair(); keyValuePair.setKey(key); keyValuePair.setValue(tokenInfo.getTokenInfo().get(key)); token.getTokenInfos().add(keyValuePair); } token.setPossibleActions(possibleActionConverter.convert( possibleActionsRuleEngine.getPossibleTokenActions( tokenInfo))); return token; }
TokenConverter { public Token convert(TokenInfo tokenInfo) { Token token = new Token(); token.setId(tokenInfo.getId()); token.setName(tokenInfo.getFriendlyName()); if (TokenInfo.SOFTWARE_MODULE_TYPE.equals(tokenInfo.getType())) { token.setType(TokenType.SOFTWARE); } else { token.setType(TokenType.HARDWARE); } token.setKeys(keyConverter.convert(tokenInfo.getKeyInfo(), tokenInfo)); Optional<TokenStatus> status = TokenStatusMapping.map(tokenInfo.getStatus()); token.setStatus(status.orElse(null)); token.setLoggedIn(tokenInfo.isActive()); token.setAvailable(tokenInfo.isAvailable()); token.setSavedToConfiguration(tokenInfo.isSavedToConfiguration()); token.setReadOnly(tokenInfo.isReadOnly()); token.setSerialNumber(tokenInfo.getSerialNumber()); token.setTokenInfos(new ArrayList<>()); for (String key: tokenInfo.getTokenInfo().keySet()) { KeyValuePair keyValuePair = new KeyValuePair(); keyValuePair.setKey(key); keyValuePair.setValue(tokenInfo.getTokenInfo().get(key)); token.getTokenInfos().add(keyValuePair); } token.setPossibleActions(possibleActionConverter.convert( possibleActionsRuleEngine.getPossibleTokenActions( tokenInfo))); return token; } }
TokenConverter { public Token convert(TokenInfo tokenInfo) { Token token = new Token(); token.setId(tokenInfo.getId()); token.setName(tokenInfo.getFriendlyName()); if (TokenInfo.SOFTWARE_MODULE_TYPE.equals(tokenInfo.getType())) { token.setType(TokenType.SOFTWARE); } else { token.setType(TokenType.HARDWARE); } token.setKeys(keyConverter.convert(tokenInfo.getKeyInfo(), tokenInfo)); Optional<TokenStatus> status = TokenStatusMapping.map(tokenInfo.getStatus()); token.setStatus(status.orElse(null)); token.setLoggedIn(tokenInfo.isActive()); token.setAvailable(tokenInfo.isAvailable()); token.setSavedToConfiguration(tokenInfo.isSavedToConfiguration()); token.setReadOnly(tokenInfo.isReadOnly()); token.setSerialNumber(tokenInfo.getSerialNumber()); token.setTokenInfos(new ArrayList<>()); for (String key: tokenInfo.getTokenInfo().keySet()) { KeyValuePair keyValuePair = new KeyValuePair(); keyValuePair.setKey(key); keyValuePair.setValue(tokenInfo.getTokenInfo().get(key)); token.getTokenInfos().add(keyValuePair); } token.setPossibleActions(possibleActionConverter.convert( possibleActionsRuleEngine.getPossibleTokenActions( tokenInfo))); return token; } @Autowired  TokenConverter(KeyConverter keyConverter,
            PossibleActionsRuleEngine possibleActionsRuleEngine,
            PossibleActionConverter possibleActionConverter); }
TokenConverter { public Token convert(TokenInfo tokenInfo) { Token token = new Token(); token.setId(tokenInfo.getId()); token.setName(tokenInfo.getFriendlyName()); if (TokenInfo.SOFTWARE_MODULE_TYPE.equals(tokenInfo.getType())) { token.setType(TokenType.SOFTWARE); } else { token.setType(TokenType.HARDWARE); } token.setKeys(keyConverter.convert(tokenInfo.getKeyInfo(), tokenInfo)); Optional<TokenStatus> status = TokenStatusMapping.map(tokenInfo.getStatus()); token.setStatus(status.orElse(null)); token.setLoggedIn(tokenInfo.isActive()); token.setAvailable(tokenInfo.isAvailable()); token.setSavedToConfiguration(tokenInfo.isSavedToConfiguration()); token.setReadOnly(tokenInfo.isReadOnly()); token.setSerialNumber(tokenInfo.getSerialNumber()); token.setTokenInfos(new ArrayList<>()); for (String key: tokenInfo.getTokenInfo().keySet()) { KeyValuePair keyValuePair = new KeyValuePair(); keyValuePair.setKey(key); keyValuePair.setValue(tokenInfo.getTokenInfo().get(key)); token.getTokenInfos().add(keyValuePair); } token.setPossibleActions(possibleActionConverter.convert( possibleActionsRuleEngine.getPossibleTokenActions( tokenInfo))); return token; } @Autowired  TokenConverter(KeyConverter keyConverter,
            PossibleActionsRuleEngine possibleActionsRuleEngine,
            PossibleActionConverter possibleActionConverter); Token convert(TokenInfo tokenInfo); List<Token> convert(Iterable<TokenInfo> tokenInfos); }
TokenConverter { public Token convert(TokenInfo tokenInfo) { Token token = new Token(); token.setId(tokenInfo.getId()); token.setName(tokenInfo.getFriendlyName()); if (TokenInfo.SOFTWARE_MODULE_TYPE.equals(tokenInfo.getType())) { token.setType(TokenType.SOFTWARE); } else { token.setType(TokenType.HARDWARE); } token.setKeys(keyConverter.convert(tokenInfo.getKeyInfo(), tokenInfo)); Optional<TokenStatus> status = TokenStatusMapping.map(tokenInfo.getStatus()); token.setStatus(status.orElse(null)); token.setLoggedIn(tokenInfo.isActive()); token.setAvailable(tokenInfo.isAvailable()); token.setSavedToConfiguration(tokenInfo.isSavedToConfiguration()); token.setReadOnly(tokenInfo.isReadOnly()); token.setSerialNumber(tokenInfo.getSerialNumber()); token.setTokenInfos(new ArrayList<>()); for (String key: tokenInfo.getTokenInfo().keySet()) { KeyValuePair keyValuePair = new KeyValuePair(); keyValuePair.setKey(key); keyValuePair.setValue(tokenInfo.getTokenInfo().get(key)); token.getTokenInfos().add(keyValuePair); } token.setPossibleActions(possibleActionConverter.convert( possibleActionsRuleEngine.getPossibleTokenActions( tokenInfo))); return token; } @Autowired  TokenConverter(KeyConverter keyConverter,
            PossibleActionsRuleEngine possibleActionsRuleEngine,
            PossibleActionConverter possibleActionConverter); Token convert(TokenInfo tokenInfo); List<Token> convert(Iterable<TokenInfo> tokenInfos);  }