<commit_before>/****************************************************************************
 * Copyright (C) 2012 HS Coburg.
 * All rights reserved.
 * Contact: ecsec GmbH (<EMAIL>)
 *
 * This file is part of the Open eCard App.
 *
 * GNU General Public License Usage
 * This file may be used under the terms of the GNU General Public
 * License version 3.0 as published by the Free Software Foundation
 * and appearing in the file LICENSE.GPL included in the packaging of
 * this file. Please review the following information to ensure the
 * GNU General Public License version 3.0 requirements will be met:
 * http://www.gnu.org/copyleft/gpl.html.
 *
 * Other Usage
 * Alternatively, this file may be used in accordance with the terms
 * and conditions contained in a signed written agreement between
 * you and ecsec GmbH.
 *
 ***************************************************************************/

package org.openecard.common.sal.state.cif;

import iso.std.iso_iec._24727.tech.schema.AccessControlListType;
import iso.std.iso_iec._24727.tech.schema.AccessRuleType;
import iso.std.iso_iec._24727.tech.schema.CardApplicationType;
import iso.std.iso_iec._24727.tech.schema.DIDInfoType;
import iso.std.iso_iec._24727.tech.schema.DataSetInfoType;
import iso.std.iso_iec._24727.tech.schema.DataSetNameListType;
import iso.std.iso_iec._24727.tech.schema.SecurityConditionType;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * This class wraps a single card application of a card info in order to make the access to attributes more efficient
 * and more user friendly.
 *
 * @author <NAME> <<EMAIL>>
 */
public class CardApplicationWrapper {

    private Map<Enum<?>, SecurityConditionType> securityConditions = new HashMap<Enum<?>, SecurityConditionType>();
    private HashMap<String, DIDInfoWrapper> didInfos = new HashMap<String, DIDInfoWrapper>();
    private final CardApplicationType cardApplication;
    private DataSetNameListType dataSetNameList = new DataSetNameListType();
    private HashMap<String, DataSetInfoWrapper> dataSetInfos = new HashMap<String, DataSetInfoWrapper>();

    /**
     *
     * @param cardApplication the CardApplication that should be wrapped
     */
    public CardApplicationWrapper(CardApplicationType cardApplication) {
	this.cardApplication = cardApplication;
    }

    /**
     *
     * @param serviceAction the ServiceAction to which the SecurityCondition should be returned
     * @return the SecurityCondition for the specified ServiceAction
     */
    public SecurityConditionType getSecurityCondition(Enum<?> serviceAction) {
	if (securityConditions.isEmpty()) {
	    for (AccessRuleType accessRule : this.cardApplication.getCardApplicationACL().getAccessRule()) {
		if (accessRule.getAction().getConnectionServiceAction() != null) {
		    securityConditions.put(accessRule.getAction().getConnectionServiceAction(),
			    accessRule.getSecurityCondition());
		} else if (accessRule.getAction().getAuthorizationServiceAction() != null) {
		    securityConditions.put(accessRule.getAction().getAuthorizationServiceAction(),
			    accessRule.getSecurityCondition());
		} else if (accessRule.getAction().getDifferentialIdentityServiceAction() != null) {
		    securityConditions.put(accessRule.getAction().getDifferentialIdentityServiceAction(),
			    accessRule.getSecurityCondition());
		} else if (accessRule.getAction().getNamedDataServiceAction() != null) {
		    securityConditions.put(accessRule.getAction().getNamedDataServiceAction(),
			    accessRule.getSecurityCondition());
		} else if (accessRule.getAction().getCryptographicServiceAction() != null) {
		    securityConditions.put(accessRule.getAction().getCryptographicServiceAction(),
			    accessRule.getSecurityCondition());
		} else if (accessRule.getAction().getCardApplicationServiceAction() != null) {
		    securityConditions.put(accessRule.getAction().getCardApplicationServiceAction(),
			    accessRule.getSecurityCondition());
		}
	    }
	}

	return securityConditions.get(serviceAction);
    }

    /**
     *
     * @return the ApplicationIdentifier of the wrapped card application
     */
    public byte[] getApplicationIdentifier() {
	return cardApplication.getApplicationIdentifier();
    }

    /**
     *
     * @param didName the name of the DID to be returned
     * @return a DIDInfoWrapper wrapping the specified DID or null if no such DID exists in the card appication
     */
    public DIDInfoWrapper getDIDInfo(String didName) {
	if (didInfos.isEmpty()) {
	    for (DIDInfoType didInfo : cardApplication.getDIDInfo()) {
		didInfos.put(didInfo.getDifferentialIdentity().getDIDName(), new DIDInfoWrapper(didInfo));
	    }
	}
	return this.didInfos.get(didName);
    }

    /**
     *
     * @return list of DIDInfos in this card application
     */
    public List<DIDInfoType> getDIDInfoList() {
	return Collections.unmodifiableList(cardApplication.getDIDInfo());
    }

    /**
     *
     * @return the ACL for this card application
     */
    public AccessControlListType getCardApplicationACL() {
	return cardApplication.getCardApplicationACL();
    }

    /**
     *
     * @return list of DataSetInfos in this card application
     */
    public List<DataSetInfoType> getDataSetInfoList() {
	return cardApplication.getDataSetInfo();
    }

    /**
     *
     * @return list of data set names in this card application
     */
    public DataSetNameListType getDataSetNameList() {
	if (dataSetNameList.getDataSetName().isEmpty()) {
	    for (DataSetInfoType dataSetInfo : cardApplication.getDataSetInfo()) {
		dataSetNameList.getDataSetName().add(dataSetInfo.getDataSetName());
	    }
	}<commit_msg>DIDInfoList is not anymore unmodifiable (DIDCreate/Delete/Update)<commit_after>/****************************************************************************
 * Copyright (C) 2012 <NAME>.
 * All rights reserved.
 * Contact: ecsec GmbH (<EMAIL>)
 *
 * This file is part of the Open eCard App.
 *
 * GNU General Public License Usage
 * This file may be used under the terms of the GNU General Public
 * License version 3.0 as published by the Free Software Foundation
 * and appearing in the file LICENSE.GPL included in the packaging of
 * this file. Please review the following information to ensure the
 * GNU General Public License version 3.0 requirements will be met:
 * http://www.gnu.org/copyleft/gpl.html.
 *
 * Other Usage
 * Alternatively, this file may be used in accordance with the terms
 * and conditions contained in a signed written agreement between
 * you and ecsec GmbH.
 *
 ***************************************************************************/

package org.openecard.common.sal.state.cif;

import iso.std.iso_iec._24727.tech.schema.AccessControlListType;
import iso.std.iso_iec._24727.tech.schema.AccessRuleType;
import iso.std.iso_iec._24727.tech.schema.CardApplicationType;
import iso.std.iso_iec._24727.tech.schema.DIDInfoType;
import iso.std.iso_iec._24727.tech.schema.DataSetInfoType;
import iso.std.iso_iec._24727.tech.schema.DataSetNameListType;
import iso.std.iso_iec._24727.tech.schema.SecurityConditionType;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * This class wraps a single card application of a card info in order to make the access to attributes more efficient
 * and more user friendly.
 *
 * @author <NAME> <<EMAIL>>
 */
public class CardApplicationWrapper {

    private Map<Enum<?>, SecurityConditionType> securityConditions = new HashMap<Enum<?>, SecurityConditionType>();
    private HashMap<String, DIDInfoWrapper> didInfos = new HashMap<String, DIDInfoWrapper>();
    private final CardApplicationType cardApplication;
    private DataSetNameListType dataSetNameList = new DataSetNameListType();
    private HashMap<String, DataSetInfoWrapper> dataSetInfos = new HashMap<String, DataSetInfoWrapper>();

    /**
     *
     * @param cardApplication the CardApplication that should be wrapped
     */
    public CardApplicationWrapper(CardApplicationType cardApplication) {
	this.cardApplication = cardApplication;
    }

    /**
     *
     * @param serviceAction the ServiceAction to which the SecurityCondition should be returned
     * @return the SecurityCondition for the specified ServiceAction
     */
    public SecurityConditionType getSecurityCondition(Enum<?> serviceAction) {
	if (securityConditions.isEmpty()) {
	    for (AccessRuleType accessRule : this.cardApplication.getCardApplicationACL().getAccessRule()) {
		if (accessRule.getAction().getConnectionServiceAction() != null) {
		    securityConditions.put(accessRule.getAction().getConnectionServiceAction(),
			    accessRule.getSecurityCondition());
		} else if (accessRule.getAction().getAuthorizationServiceAction() != null) {
		    securityConditions.put(accessRule.getAction().getAuthorizationServiceAction(),
			    accessRule.getSecurityCondition());
		} else if (accessRule.getAction().getDifferentialIdentityServiceAction() != null) {
		    securityConditions.put(accessRule.getAction().getDifferentialIdentityServiceAction(),
			    accessRule.getSecurityCondition());
		} else if (accessRule.getAction().getNamedDataServiceAction() != null) {
		    securityConditions.put(accessRule.getAction().getNamedDataServiceAction(),
			    accessRule.getSecurityCondition());
		} else if (accessRule.getAction().getCryptographicServiceAction() != null) {
		    securityConditions.put(accessRule.getAction().getCryptographicServiceAction(),
			    accessRule.getSecurityCondition());
		} else if (accessRule.getAction().getCardApplicationServiceAction() != null) {
		    securityConditions.put(accessRule.getAction().getCardApplicationServiceAction(),
			    accessRule.getSecurityCondition());
		}
	    }
	}

	return securityConditions.get(serviceAction);
    }

    /**
     *
     * @return the ApplicationIdentifier of the wrapped card application
     */
    public byte[] getApplicationIdentifier() {
	return cardApplication.getApplicationIdentifier();
    }

    /**
     *
     * @param didName the name of the DID to be returned
     * @return a DIDInfoWrapper wrapping the specified DID or null if no such DID exists in the card appication
     */
    public DIDInfoWrapper getDIDInfo(String didName) {
	if (didInfos.isEmpty()) {
	    for (DIDInfoType didInfo : cardApplication.getDIDInfo()) {
		didInfos.put(didInfo.getDifferentialIdentity().getDIDName(), new DIDInfoWrapper(didInfo));
	    }
	}
	return this.didInfos.get(didName);
    }

    /**
     *
     * @return list of DIDInfos in this card application
     */
    public List<DIDInfoType> getDIDInfoList() {
	return cardApplication.getDIDInfo();
    }

    /**
     *
     * @return the ACL for this card application
     */
    public AccessControlListType getCardApplicationACL() {
	return cardApplication.getCardApplicationACL();
    }

    /**
     *
     * @return list of DataSetInfos in this card application
     */
    public List<DataSetInfoType> getDataSetInfoList() {
	return cardApplication.getDataSetInfo();
    }

    /**
     *
     * @return list of data set names in this card application
     */
    public DataSetNameListType getDataSetNameList() {
	if (dataSetNameList.getDataSetName().isEmpty()) {
	    for (DataSetInfoType dataSetInfo : cardApplication.getDataSetInfo()) {
		dataSetNameList.getDataSetName().add(dataSetInfo.getDataSetName());
	    }
	}
{'fraction_non_alphanumeric': 0.12210471112664976, 'fraction_numerical': 0.0075168254523206015, 'mean_word_length': 4.331780055917987, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5015695', 'n_tokens_mistral': 3236, 'n_tokens_neox': 3016, 'n_words': 774}