Class ContractManager

  • All Implemented Interfaces:
    CommonManager

    public final class ContractManager
    extends AbstractManager
    This class is responsible to manage contracts: add, remove and modify.
    • Constructor Detail

      • ContractManager

        public ContractManager​(SQLiteDataSource dataSource)
        Instantiates an Contract Manager that uses the Backend configuration provided.
    • Method Detail

      • newPrivateContract

        public ContractID newPrivateContract​(Contract newContract)
                                      throws ParseException
        Method that creates a new private contract with the provided account. The contract contains a set of Interfaces with its accessible methods, operations and properties. The Interfaces must refer to Metaclasses of the same Namespace, which is also provided in the method.
        Parameters:
        newContract - Information of the contract to create
        Returns:
        the id of the contract
        Throws:
        ParseException - parse exception.
      • newPublicContract

        public ContractID newPublicContract​(Contract newContract)
                                     throws ParseException
        Method that creates a new public contract. The contract contains a set of Interfaces with its accessible methods, operations and properties. The Interfaces must refer to Metaclasses of the same Namespace, which is also provided in the method.
        Parameters:
        newContract - Information of the contract to create
        Returns:
        the id of the contract
        Throws:
        ParseException - parse exception.
      • registerToPublicContract

        public void registerToPublicContract​(AccountID applicantAccountID,
                                             ContractID contractID)
        Method that allows an account to register to a public contract.
        Parameters:
        applicantAccountID - the id of the applicant account
        contractID - the id of the contract
        Throws:
        Exception - if some exception occurs:
        ContractNotExistException: if the contract does not exist
        ContractNotPublicException: if the contract is not public
        ContractNotActiveException: if the contract has expired
        AccountAlreadyRegisteredInContract if the account is already registered to the contract
      • checkActiveContracts

        public void checkActiveContracts​(HashSet<ContractID> modelContracts)
        This method checks whether the given contracts are active
        Parameters:
        modelContracts - Contracts to be checked
        Throws:
        Exception - if some exception occurs:
        ContractNotExistException: if some contract does not exist.
        ContractNotActiveException: if some contract is not active.
      • checkNamespaceHasNoContracts

        public boolean checkNamespaceHasNoContracts​(NamespaceID namespaceID)
        This method checks if there is no contract associated with the provided namespace
        Parameters:
        namespaceID - the namespace to be checked
        Returns:
        true if there is no contract related with the namespace, false otherwise
        Throws:
        Exception - if some exception occurs
      • checkInterfaceHasNoContracts

        public boolean checkInterfaceHasNoContracts​(InterfaceID interfaceID)
        This method checks that the provided interfaceID is not accessible from any contract.
        Parameters:
        interfaceID - the id of the interface
        Returns:
        true if there is no contract related with the interface, false otherwise
        Throws:
        Exception - if some exception occurs
      • checkImplementationHasNoContracts

        public boolean checkImplementationHasNoContracts​(ImplementationID implementationID)
        This method checks if the provided implementation is accessible from any contract.
        Parameters:
        implementationID - the id of the implementation
        Returns:
        true if there is no contract related with the implementation, false otherwise
        Throws:
        Exception - if some exception occurs
      • checkImplementationHasContractForAccount

        public boolean checkImplementationHasContractForAccount​(ImplementationID implementationID,
                                                                AccountID accountID)
        This method checks if the provided implementation is accessible from any contract of the user provided.
        Parameters:
        implementationID - the id of the implementation
        accountID - ID of account to check.
        Returns:
        true if there is a contract related with the implementation an user, false otherwise
        Throws:
        Exception - if some exception occurs
      • checkInterfacesInActiveContractsForAccount

        public boolean checkInterfacesInActiveContractsForAccount​(AccountID accountID,
                                                                  Map<ContractID,​InterfaceID> interfacesInContracts)
        This method checks whether the provided account is registered in the contracts provided and such contracts are still active and contain a specific interface.
        Parameters:
        accountID - the account ID
        interfacesInContracts - the interface to be checked for each contract
        Returns:
        true if the provided account is registered in all the contracts provided, they are active, and every contract contains the corresponding interface provided
        Throws:
        Exception - if some exception occurs:
        ContractNotExistException: if the contract does not exist
      • checkInterfacesInActiveContractsForAccountAndReturnContractsInfo

        public Map<ContractID,​Contract> checkInterfacesInActiveContractsForAccountAndReturnContractsInfo​(AccountID accountID,
                                                                                                               Map<ContractID,​InterfaceID> interfacesInContract)
        This method checks whether the provided account is registered in the contracts provided and such contracts are still active and contain a specific interface. Finally returns the info of the contracts.
        Parameters:
        accountID - ID of the account
        interfacesInContract - the interface to be checked for each contract
        Returns:
        info of the contracts
        Throws:
        Exception - if some exception occurs
      • getContractInfo

        public Contract getContractInfo​(ContractID contractID)
        This method returns the info of a contract
        Parameters:
        contractID - ID of the contract
        Returns:
        info of the contract
        Throws:
        Exception - if some exception occurs:
        ContractNotExistException: if the contract does not exist
      • getInfoOfSomeActiveContractsForAccount

        public LinkedHashMap<ContractID,​Contract> getInfoOfSomeActiveContractsForAccount​(List<ContractID> contractsIDs,
                                                                                               AccountID accountID)
        This method returns the info of the contracts if they are still active and the given account is registered on them.
        Parameters:
        contractsIDs - IDs of the contracts
        accountID - ID of the account that must be registered in the contract
        Returns:
        the information about the contracts
        Throws:
        Exception - if some exception occurs:
        ContractNotExistException: if the contract does not exist
        AccountNotRegisteredInContract: if the account is not registered in the contract
        ContractNotActiveException: if the contract is not active
      • getInfoOfAllActiveContractsForAccount

        public Map<ContractID,​Contract> getInfoOfAllActiveContractsForAccount​(AccountID accountID)
        This method returns the info of all the active contracts which account is applicant of.
        Parameters:
        accountID - ID of the account that must be registered in the contract
        Returns:
        the information about the contracts
        Throws:
        Exception - if some exception occurs
      • getContractIDsOfProvider

        public Map<ContractID,​Contract> getContractIDsOfProvider​(NamespaceID namespaceIDofProvider)
        Get info of all contracts of the namespace provided indexed by their id.
        Parameters:
        namespaceIDofProvider - the namespace of the contract
        Returns:
        The info of the contracts of the account provided in the namespace provided
        Throws:
        Exception - if some exception occurs
      • getPublicContractIDsOfProvider

        public Map<ContractID,​Contract> getPublicContractIDsOfProvider​(NamespaceID namespaceIDofProvider)
        Get info of all contracts of the namespace provided indexed by their id.
        Parameters:
        namespaceIDofProvider - the namespace of the contract
        Returns:
        The info of the contracts of the account provided in the namespace provided
        Throws:
        Exception - if some exception occurs
      • getContractIDsOfApplicant

        public Map<ContractID,​Contract> getContractIDsOfApplicant​(AccountID applicantAccountID)
        Get all contract IDs of the user provided (as applicant)
        Parameters:
        applicantAccountID - the applicant user
        Returns:
        The info of the contracts of the user (as applicant)
        Throws:
        Exception - if some exception occurs
      • getContractIDsOfProvider

        public Map<ContractID,​Contract> getContractIDsOfProvider​(AccountID providerAccountID)
        Get all contract IDs of the user provided (as provider)
        Parameters:
        providerAccountID - the provider user
        Returns:
        The info of the contracts of the user (as provider)
        Throws:
        Exception - if some exception occurs
      • getContractIDsOfApplicantWithProvider

        public Map<ContractID,​Contract> getContractIDsOfApplicantWithProvider​(AccountID applicantAccountID,
                                                                                    NamespaceID namespaceIDofProvider)
        Get all contract IDs of the user provided (as applicant) with a namespace provider.
        Parameters:
        applicantAccountID - the applicant user.
        namespaceIDofProvider - the ID of the namespace provider.
        Returns:
        The info of the contracts of the user (as applicant) with the given namespace.
        Throws:
        Exception - if some exception occurs
      • getInfoOfSubsetOfInterfacesThatAreInActiveContractsForAccount

        public Map<ContractID,​InterfaceInContract> getInfoOfSubsetOfInterfacesThatAreInActiveContractsForAccount​(AccountID accountID,
                                                                                                                       Map<ContractID,​InterfaceID> interfacesInContracts)
        This method checks whether the provided account is registered in the contracts provided and such contracts are still active and contain the given interfaces. Finally, returns the information of such interfaces per contract.
        Parameters:
        accountID - the account ID
        interfacesInContracts - the multiple interfaces per contract to be retrieved
        Returns:
        all the info related with the given interfaces in contract (if contracts are active and account is actually registered on them)
        Throws:
        Exception - if some exception occurs:
        ContractNotExistException: if the contract does not exist
        AccountNotRegisteredInContract: if the account is not registred in some of the contracts
        ContractNotActiveException: if any of the contracts is not active
        InterfaceNotInContractException: if any of the interfaces is not in the corresponding contract
      • getInfoOfMultipleContractsPerActiveContractsForAccount

        public Map<ContractID,​Tuple<Map<InterfaceID,​InterfaceInContract>,​Calendar>> getInfoOfMultipleContractsPerActiveContractsForAccount​(AccountID accountID,
                                                                                                                                                             Set<ContractID> contracts)
        This method checks whether the provided account is registered in the contracts provided and such contracts are still active. Finally, returns the information of the interfaces in contract.
        Parameters:
        accountID - the account ID
        contracts - the multiple contracts to be checked
        Returns:
        all the info related with the given contracts (if contracts are active and account is actually registered to them)
        Throws:
        Exception - if some exception occurs:
        ContractNotExistException: if the contract does not exist
        AccountNotRegisteredInContract: if the account is not registred in some of the contracts
        ContractNotActiveException: if any of the contracts is not active
      • getInfoOfMultipleInterfacesPerActiveContractsForAccount

        public Map<ContractID,​Tuple<Map<InterfaceID,​InterfaceInContract>,​Calendar>> getInfoOfMultipleInterfacesPerActiveContractsForAccount​(AccountID accountID,
                                                                                                                                                              Map<ContractID,​HashSet<InterfaceID>> interfacesInContracts)
        This method returns the information of those interfaces in (still active) contract having the given account registered on them. If the any of the conditions is not satisfied, no error is produced but the info of such interface in contract is not returned.
        Parameters:
        accountID - the account ID
        interfacesInContracts - the interfaces per contract to be retrieved
        Returns:
        from the given interfaces in contracts, the info of those that are in active contracts and account is registered
        Throws:
        Exception - if some exception occurs.
      • getDbHandler

        public ContractManagerDB getDbHandler()
        Method used for unit testing.
        Returns:
        The db handler reference of this manager.