text:
package org.oscm.domobjects;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import javax.persistence.PrePersist;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

import org.oscm.domobjects.annotations.BusinessKey;
import org.oscm.domobjects.enums.LocalizedObjectTypes;
import org.oscm.domobjects.enums.OrganizationReferenceType;
import org.oscm.internal.types.enumtypes.OrganizationRoleType;
import org.oscm.internal.types.enumtypes.SettingType;
import org.oscm.internal.types.enumtypes.SubscriptionStatus;
import org.oscm.internal.types.enumtypes.TriggerType;
import org.oscm.internal.types.exception.IllegalArgumentException;
import org.oscm.internal.types.exception.SaaSSystemException;
import org.oscm.types.enumtypes.UdaTargetType;

/**
 * We call the one who registers at the SaaS portal a organization. We consider
 * this one also as the contracting party in the legal sense. Part of a
 * organization#s data is the payment information to be used for collecting the
 * subscription fees. (Entering the payment information is only mandatory if the
 * organization subscribes a chargeable product.)
 *
 * @author schmid
 */
@Entity
@Table(uniqueConstraints = @UniqueConstraint(columnNames = {
        "organizationId" }))
@NamedQueries({
        @NamedQuery(name = "Organization.getAdministrators", query = "SELECT pu FROM PlatformUser pu, RoleAssignment ra WHERE pu.organization.key=:orgkey and ra.user.key=pu.key and ra.userRole.dataContainer.roleName=org.oscm.internal.types.enumtypes.UserRoleType.ORGANIZATION_ADMIN"),
        @NamedQuery(name = "Organization.findByBusinessKey", query = "SELECT c FROM Organization c WHERE c.dataContainer.organizationId=:organizationId"),
        @NamedQuery(name = "Organization.getAllOrganizations", query = "SELECT c FROM Organization c"),
        @NamedQuery(name = "Organization.getAllSuppliers", query = "SELECT c FROM Organization c INNER JOIN c.grantedRoles otr INNER JOIN otr.organizationRole r WHERE r.dataContainer.roleName = org.oscm.internal.types.enumtypes.OrganizationRoleType.SUPPLIER"),
        @NamedQuery(name = "Organization.getForSupplierKey", query = "SELECT c FROM Organization c, OrganizationReference r WHERE r.target=c AND r.sourceKey=:supplierKey AND r.dataContainer.referenceType = :referenceType ORDER BY c.key ASC"),
        @NamedQuery(name = "Organization.getForSupplierKeyAndProduct", query = "SELECT c FROM Organization c, OrganizationReference r, Product p WHERE r.target=c AND r.sourceKey=:supplierKey AND r.dataContainer.referenceType = org.oscm.domobjects.enums.OrganizationReferenceType.SUPPLIER_TO_CUSTOMER AND c = p.targetCustomer AND p.template = :product AND NOT EXISTS (SELECT s.key FROM Subscription s WHERE s.product = p)"),
        @NamedQuery(name = "Organization.getForOffererKeyAndSubscriptionId", query = "SELECT c FROM Organization c, OrganizationReference r, Subscription sub WHERE r.target=c AND r.sourceKey=:offererKey AND r.dataContainer.referenceType IN (org.oscm.domobjects.enums.OrganizationReferenceType.SUPPLIER_TO_CUSTOMER,org.oscm.domobjects.enums.OrganizationReferenceType.BROKER_TO_CUSTOMER,org.oscm.domobjects.enums.OrganizationReferenceType.RESELLER_TO_CUSTOMER) AND sub.organization = c AND sub.dataContainer.subscriptionId = :subscriptionId AND sub.dataContainer.status IN (:states)"),
        @NamedQuery(name = "Organization.findOrganizationsByIdAndRole", query = "SELECT DISTINCT o FROM Organization o, OrganizationToRole o2r, OrganizationRole r where o.dataContainer.organizationId like :organizationId and o = o2r.organization and o2r.organizationRole = r and r.dataContainer.roleName IN (:organizationRoleTypes)"),
        @NamedQuery(name = "Organization.countOrgsWithSameDN", query = "SELECT COUNT (DISTINCT organization) FROM Organization organization WHERE organization.dataContainer.distinguishedName = :distinguishedName AND organization != :organization"),
        @NamedQuery(name = "Organization.getLdapManagedOrganizations", query = "SELECT organization FROM Organization organization WHERE organization.dataContainer.remoteLdapActive=true"),
        @NamedQuery(name = "Organization.getOrgsForDN", query = "SELECT DISTINCT organization FROM Organization organization WHERE organization.dataContainer.distinguishedName IN (:dn)") })
@BusinessKey(attributes = { "organizationId" })
public class Organization extends DomainObjectWithHistory<OrganizationData> {

    private static final long serialVersionUID = 1L;

    private static final List<LocalizedObjectTypes> LOCALIZATION_TYPES = Collections
            .unmodifiableList(Arrays
                    .asList(LocalizedObjectTypes.ORGANIZATION_DESCRIPTION));

    public Organization() {
        super();
        dataContainer = new OrganizationData();
    }

    /**
     * The list with all active setting types of the current organization which
     * define a mapping of an LDAP attribute to a user property.
     *
     * @see OrganizationRoleType#CUSTOMER
     */
    @Transient
    private List<SettingType> ldapUserAttributes;

    /**
     * 1:n relation to the owned marketplaces: CascadeType: REMOVE
     *
     * @see OrganizationRoleType#SUPPLIER
     */
    @OneToMany(mappedBy = "organization", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
    private List<Marketplace> marketplaces = new ArrayList<>();

    /**
     * 1:n relation to PlatformUser: the users registered for the organization.
     * No cascading option.
     */
    @OneToMany(mappedBy = "organization", fetch = FetchType.LAZY)
    @OrderBy
    private List<PlatformUser> platformUsers = new ArrayList<>();

    /**
     * 1:n relation to Subscription: the subscriptions of the organization.
     * CascadeType: REMOVE
     *
     * @see OrganizationRoleType#CUSTOMER
     */
    @OneToMany(mappedBy = "organization", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
    @OrderBy
    private List<Subscription> subscriptions = new ArrayList<>();

    /**
     * 1:n relation to OrganizationReference which references the sources (this
     * organization is the target).
     */
    @OneToMany(cascade = CascadeType.REMOVE, mappedBy = "target", fetch = FetchType.LAZY)
    @OrderBy
    private List<OrganizationReference> sources = new ArrayList<>();

    /**
     * 1:n relation to OrganizationReference which references the targets (this
     * organization is the source).
     */
    @OneToMany(cascade = CascadeType.REMOVE, mappedBy = "source", fetch = FetchType.LAZY)
    @OrderBy
    private List<OrganizationReference> targets = new ArrayList<>();

    /**
     * 1:n relation to Product: the organization is the supplier of the
     * marketing product. CascadeType: REMOVE
     *
     * @see OrganizationRoleType#SUPPLIER
     */
    @OneToMany(mappedBy = "vendor", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
    @OrderBy
    private List<Product> products = new ArrayList<>();

    /**
     * 1:n relation to TechnicalProduct: the organization is technology provider
     * of the technical product. CascadeType: REMOVE
     *
     * @see OrganizationRoleType#TECHNOLOGY_PROVIDER
     */
    @OneToMany(mappedBy = "organization", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
    @OrderBy
    private List<TechnicalProduct> technicalProducts = new ArrayList<>();

    @OneToMany(mappedBy = "organization", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
    @OrderBy
    private Set<OrganizationToRole> grantedRoles = new HashSet<>();

    @OneToMany(mappedBy = "organization", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
    @OrderBy
    private List<OrganizationSetting> organizationSettings = new ArrayList<>();

    @OneToMany(mappedBy = "organization", fetch = FetchType.LAZY)
    @OrderBy
    private List<TriggerDefinition> triggerDefinitions = new ArrayList<>();

    @OneToMany(mappedBy = "organization", fetch = FetchType.LAZY)
    @OrderBy
    private List<UdaDefinition> udaDefinitions = new ArrayList<>();

    @OneToMany(mappedBy = "organization", fetch = FetchType.LAZY)
    @OrderBy
    private List<PSPAccount> pspAccounts = new ArrayList<>();

    /**
     * @see OrganizationRoleType#SUPPLIER
     */
    @OneToMany(mappedBy = "organization", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<OrganizationToCountry> organizationToCountries = new ArrayList<>();

    @ManyToOne(fetch = FetchType.LAZY)
    private SupportedCountry domicileCountry;

    /**
     * @see OrganizationRoleType#SUPPLIER
     */
    @OneToMany(mappedBy = "owningOrganization", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
    @OrderBy
    private List<VatRate> definedVatRates = new ArrayList<>();

    /**
     * The billing contact information data stored for the current organization.
     */
    @OneToMany(mappedBy = "organization", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
    @OrderBy
    private List<BillingContact> billingContacts = new ArrayList<>();

    /**
     * The payment information stored for the current organization.
     */
    @OneToMany(mappedBy = "organization", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
    @OrderBy
    private List<PaymentInfo> paymentInfos = new ArrayList<>();

    @OneToMany(mappedBy = "organization", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
    private List<MarketplaceToOrganization> marketplaceToOrganizations = new ArrayList<>();

    @OneToOne(optional = true, cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
    private RevenueShareModel operatorPriceModel;

    @OneToMany(mappedBy = "organization", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
    @OrderBy
    private List<UserGroup> userGroups = new ArrayList<>();

    @OneToMany(mappedBy = "organization", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
    @OrderBy
    private List<MarketplaceAccess> marketplaceAccesses = new ArrayList<>();

    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    @JoinColumn(name = "tenant_tkey")
    private Tenant tenant;

    /**
     * OrganizationID of the platform operator. The platform operator is created
     * by the setup script.
     */
    public static final String PLATFORM_OPERATOR = "PLATFORM_OPERATOR";

    /*
     * Fill registration date (if not already set)
     */
    @PrePersist
    public void fillRegistrationDate() {
        if (getRegistrationDate() == 0) {
            setRegistrationDate(System.currentTimeMillis());
        }
    }

    /**
     * Refer to {@link OrganizationData#address}
     */
    public String getAddress() {
        return dataContainer.getAddress();
    }

    /**
     * Refer to {@link OrganizationData#email}
     */
    public String getEmail() {
        return dataContainer.getEmail();
    }

    /**
     * Refer to {@link OrganizationData#email}
     */
    public void setEmail(String email) {
        dataContainer.setEmail(email);
    }

    /**
     * Refer to {@link OrganizationData#name}
     */
    public String getName() {
        return dataContainer.getName();
    }

    /**
     * Refer to {@link OrganizationData#phone}
     */
    public String getPhone() {
        return dataContainer.getPhone();
    }

    /**
     * Refer to {@link OrganizationData#url}
     */
    public String getUrl() {
        return dataContainer.getUrl();
    }

    /**
     * Refer to {@link OrganizationData#address}
     */
    public void setAddress(String address) {
        dataContainer.setAddress(address);
    }

    /**
     * Refer to {@link OrganizationData#name}
     */
    public void setName(String name) {
        dataContainer.setName(name);
    }

    /**
     * Refer to {@link OrganizationData#phone}
     */
    public void setPhone(String phone) {
        dataContainer.setPhone(phone);
    }

    /**
     * Refer to {@link OrganizationData#url}
     */
    public void setUrl(String url) {
        dataContainer.setUrl(url);
    }

    /**
     * Refer to {@link OrganizationData#organizationId}
     */
    public String getOrganizationId() {
        return dataContainer.getOrganizationId();
    }

    /**
     * Refer to {@link OrganizationData#deregistrationDate}
     */
    public Long getDeregistrationDate() {
        return dataContainer.getDeregistrationDate();
    }

    /**
     * Refer to {@link OrganizationData#registrationDate}
     */
    public long getRegistrationDate() {
        return dataContainer.getRegistrationDate();
    }

    /**
     * Refer to {@link OrganizationData#organizationId}
     */
    public void setOrganizationId(String organizationId) {
        dataContainer.setOrganizationId(organizationId);
    }

    /**
     * Refer to {@link OrganizationData#deregistrationDate}
     */
    public void setDeregistrationDate(Long deregistrationDate) {
        dataContainer.setDeregistrationDate(deregistrationDate);
    }

    /**
     * Refer to {@link OrganizationData#registrationDate}
     */
    public void setRegistrationDate(long registrationDate) {
        dataContainer.setRegistrationDate(registrationDate);
    }

    /**
     * Refer to {@link OrganizationData#locale}
     */
    public String getLocale() {
        return dataContainer.getLocale();
    }

    /**
     * Refer to {@link OrganizationData#locale}
     */
    public void setLocale(String locale) {
        dataContainer.setLocale(locale);
    }

    public void setPlatformUsers(List<PlatformUser> platformUsers) {
        this.platformUsers = platformUsers;
    }

    public void addPlatformUser(PlatformUser platformUser) {
        platformUsers.add(platformUser);
    }

    /**
     * Returns a list of all platform users of this organization. The list does
     * not include users that have been created on the behalf of other users.
     * These users should be excluded in the UI.
     *
     * @return List of platform users
     */
    public List<PlatformUser> getVisiblePlatformUsers() {
        List<PlatformUser> result = new ArrayList<>();
        for (PlatformUser user : getPlatformUsers()) {
            if (!user.isOnBehalfUser()) {
                result.add(user);
            }
        }
        return result;
    }

    /**
     * Returns all platform users of this organization. The result list includes
     * users that have been created on the behalf of other users also. These
     * users should be excluded in the UI.
     *
     * @return List of platform users
     */
    public List<PlatformUser> getPlatformUsers() {
        return platformUsers;
    }

    /**
     * Returns all administrators of this organization. The result list includes
     * users that have been created on the behalf of other users also. These
     * users should be excluded in the UI.
     *
     * @return List of platform users
     */
    public List<PlatformUser> getOrganizationAdmins() {
        List<PlatformUser> result = new ArrayList<>();
        for (PlatformUser platformUser : getPlatformUsers()) {
            if (platformUser.isOrganizationAdmin()) {
                result.add(platformUser);
            }
        }
        return result;
    }

    public void setSubscriptions(List<Subscription> subscriptions) {
        this.subscriptions = subscriptions;
    }

    public List<Subscription> getSubscriptions() {
        return subscriptions;
    }

    /**
     * Returns a list of all usable subscriptions. A subscription is considered
     * usable if a user can eventually subscribe to it.
     */
    public List<Subscription> getUsableSubscriptions() {
        List<Subscription> usableSubscriptions = new ArrayList<>(subscriptions);
        for (Iterator<Subscription> i = usableSubscriptions.iterator(); i
                .hasNext();) {
            Subscription subscription = i.next();
            if (!subscription.isUsable()) {
                i.remove();
            }
        }
        return usableSubscriptions;
    }

    public List<Product> getProducts() {
        return products;
    }

    public void setProducts(List<Product> products) {
        this.products = products;
    }

    public List<TechnicalProduct> getTechnicalProducts() {
        return technicalProducts;
    }

    public void setTechnicalProducts(List<TechnicalProduct> technicalProducts) {
        this.technicalProducts = technicalProducts;
    }

    public List<Organization> getTechnologyProviders() {
        List<Organization> result = new ArrayList<>(getSources().size());
        for (OrganizationReference ref : getSources()) {
            if (ref.getReferenceType() == OrganizationReferenceType.TECHNOLOGY_PROVIDER_TO_SUPPLIER) {
                result.add(ref.getSource());
            }
        }
        return result;
    }

    public List<Organization> getGrantedSuppliers() {
        List<Organization> result = new ArrayList<>(getTargets().size());
        for (OrganizationReference ref : getTargets()) {
            if (ref.getReferenceType() == OrganizationReferenceType.TECHNOLOGY_PROVIDER_TO_SUPPLIER) {
                result.add(ref.getTarget());
            }
        }
        return result;
    }

    public List<Organization> getCustomersOfSupplier() {
        List<Organization> result = new ArrayList<>(getTargets().size());
        for (OrganizationReference ref : getTargets()) {
            if (ref.getReferenceType() == OrganizationReferenceType.SUPPLIER_TO_CUSTOMER) {
                result.add(ref.getTarget());
            }
        }
        return result;
    }

    public List<Organization> getCustomersOfBroker() {
        List<Organization> result = new ArrayList<>(getTargets().size());
        for (OrganizationReference ref : getTargets()) {
            if (ref.getReferenceType() == OrganizationReferenceType.BROKER_TO_CUSTOMER) {
                result.add(ref.getTarget());
            }
        }
        return result;
    }

    public List<Organization> getCustomersOfReseller() {
        List<Organization> result = new ArrayList<>(getTargets().size());
        for (OrganizationReference ref : getTargets()) {
            if (ref.getReferenceType() == OrganizationReferenceType.RESELLER_TO_CUSTOMER) {
                result.add(ref.getTarget());
            }
        }
        return result;
    }

    public List<Organization> getSuppliersOfCustomer() {
        List<Organization> result = new ArrayList<>(getSources().size());
        for (OrganizationReference ref : getSources()) {
            if (ref.getReferenceType() == OrganizationReferenceType.SUPPLIER_TO_CUSTOMER) {
                result.add(ref.getSource());
            }
        }
        return result;
    }

    public List<Organization> getVendorsOfCustomer() {
        List<Organization> result = new ArrayList<>(getSources().size());
        for (OrganizationReference ref : getSources()) {
            if ((ref.getReferenceType() == OrganizationReferenceType.SUPPLIER_TO_CUSTOMER)
                    || (ref.getReferenceType() == OrganizationReferenceType.BROKER_TO_CUSTOMER)
                    || (ref.getReferenceType() == OrganizationReferenceType.RESELLER_TO_CUSTOMER)) {
                result.add(ref.getSource());
            }
        }
        return result;
    }

    public Set<OrganizationToRole> getGrantedRoles() {
        return grantedRoles;
    }

    public void setGrantedRoles(Set<OrganizationToRole> grantedRoles) {
        this.grantedRoles = grantedRoles;
    }

    public Set<OrganizationRoleType> getGrantedRoleTypes() {
        Set<OrganizationRoleType> result = new HashSet<>();
        for (OrganizationToRole orgToRole : getGrantedRoles()) {
            result.add(orgToRole.getOrganizationRole().getRoleName());
        }
        return result;
    }

    /**
     * Checks if the organization has been granted the given role.
     *
     * Any organization has a role CUSTOMER
     *
     * @param roleToCheckFor
     *            The role the organization is supposed to be granted.
     * @return <code>true</code> in case the organization has been granted the
     *         given role, <code>false</code> otherwise.
     */
    public boolean hasRole(OrganizationRoleType roleToCheckFor) {
        for (OrganizationToRole orgToRole : grantedRoles) {
            if (orgToRole.getOrganizationRole()
                    .getRoleName() == roleToCheckFor) {
                return true;
            }
        }
        return false;
    }

    public void setOrganizationSettings(
            List<OrganizationSetting> organizationSettings) {
        ldapUserAttributes = null;
        this.organizationSettings = organizationSettings;
    }

    public List<OrganizationSetting> getOrganizationSettings() {
        return organizationSettings;
    }

    /**
     * Checks if a remote LDAP has been activated for the organization.
     *
     * @return <code>true</code> in case a remote LDAP has been activated for
     *         the organization, <code>false</code> otherwise.
     */
    public boolean isRemoteLdapActive() {
        return dataContainer.isRemoteLdapActive();
    }

    /**
     * Defines if the organization supports users managed in a remote LDAP
     * system or not.
     *
     * @param remoteLdapActive
     *            <code>true</code> in case the organization users are managed
     *            in an external LDAP system, <code>false</code> otherwise.
     */
    public void setRemoteLdapActive(boolean remoteLdapActive) {
        dataContainer.setRemoteLdapActive(remoteLdapActive);
    }

    /**
     * @return The list with all active setting types of the current
     *         Organization which define a mapping of an LDAP attribute to a
     *         user property.
     */
    public List<SettingType> getLdapUserAttributes() {
        if (ldapUserAttributes == null) {
            if (getOrganizationSettings() != null) {
                ldapUserAttributes = new ArrayList<>();
                for (OrganizationSetting setting : getOrganizationSettings()) {
                    if (SettingType.LDAP_ATTRIBUTES
                            .contains(setting.getSettingType())) {
                        ldapUserAttributes.add(setting.getSettingType());
                    }
                }
            }
        }
        return ldapUserAttributes;
    }

    /**
     * Returns the organization reference to payment type objects valid in the
     * context of the defining organization with the given identifier.
     *
     * @param definingOrgId
     *            The identifier of the defining organization.
     * @return The payment references.
     */
    public List<OrganizationRefToPaymentType> getPaymentTypes(
            String definingOrgId) {
        List<OrganizationRefToPaymentType> result = new ArrayList<>();
        for (OrganizationReference defOrgRef : getSources()) {
            String organizationId = defOrgRef.getSource().getOrganizationId();
            if (organizationId != null
                    && organizationId.equals(definingOrgId)) {
                // get org to payment ref and add to list
                result.addAll(defOrgRef.getPaymentTypes());
            }
        }
        return result;
    }

    /**
     * Reads the payment types added for this organization in the context of a
     * certain role
     *
     * @param usedAsDefault
     *            <code>true</code> if the configured default payment types
     *            should be returned; <code>false</code> if the available
     *            payment types should be returned
     * @param role
     *            the context role - a customer can have available payment types
     *            as well as a supplier
     * @param definingOrgId
     *            The identifier of the defining organization.
     * @return the list of <code>OrganizationToPaymentType</code>
     */
    public List<OrganizationRefToPaymentType> getPaymentTypes(
            boolean usedAsDefault, OrganizationRoleType role,
            String definingOrgId) {
        List<OrganizationRefToPaymentType> types = getPaymentTypes(
                definingOrgId);
        List<OrganizationRefToPaymentType> result = new ArrayList<>();
        for (OrganizationRefToPaymentType ref : types) {
            if ((!usedAsDefault
                    || (usedAsDefault && ref.isUsedAsDefault() == true))
                    && ref.getOrganizationRole().getRoleName() == role) {
                result.add(ref);
            }
        }
        return result;
    }

    /**
     * Reads the service default payment types added for this organization in
     * the context of a certain role.
     *
     * @return the list of <code>OrganizationRefToPaymentType</code>
     */
    public List<OrganizationRefToPaymentType> getDefaultServicePaymentTypes() {

        List<OrganizationRefToPaymentType> types = getPaymentTypes(
                OrganizationRoleType.PLATFORM_OPERATOR.name());
        List<OrganizationRefToPaymentType> result = new ArrayList<>();
        for (OrganizationRefToPaymentType ref : types) {
            if ((ref.isUsedAsServiceDefault() == true)
                    && (OrganizationRoleType.SUPPLIER
                            .equals(ref.getOrganizationRole().getRoleName())
                            || OrganizationRoleType.RESELLER.equals(
                                    ref.getOrganizationRole().getRoleName()))) {
                result.add(ref);
            }
        }
        return result;
    }

    public void setDistinguishedName(String distinguishedName) {
        dataContainer.setDistinguishedName(distinguishedName);
    }

    public String getDistinguishedName() {
        return dataContainer.getDistinguishedName();
    }

    public String getSupportEmail() {
        return dataContainer.getSupportEmail();
    }

    public void setSupportEmail(String supportEmail) {
        dataContainer.setSupportEmail(supportEmail);
    }

    public List<TriggerDefinition> getTriggerDefinitions() {
        return triggerDefinitions;
    }

    public void setTriggerDefinitions(
            List<TriggerDefinition> triggerDefinitions) {
        this.triggerDefinitions = triggerDefinitions;
    }

    /**
     * Returns the trigger definition stored for the current organization that
     * is configured to suspend the processing of BES. If more than one entry
     * should be there, a system exception will be thrown.
     *
     * @param type
     *            The type the trigger must have.
     *
     * @return The suspending trigger definition, <code>null</code> if none
     *         exists.
     */
    public TriggerDefinition getSuspendingTriggerDefinition(TriggerType type) {
        TriggerDefinition result = null;
        for (TriggerDefinition td : this.triggerDefinitions) {
            if (td.getType() == type && td.isSuspendProcess()) {
                if (result != null) {
                    throw new SaaSSystemException(String.format(
                            "More than one suspending trigger definition found for organization '%s'. Data is inconsistent, operation aborted.",
                            String.valueOf(getKey())));
                }
                result = td;
            }
        }
        return result;
    }

    @Override
    String toStringAttributes() {
        return String.format(", organizationId='%s'", getOrganizationId());
    }

    public void setUdaDefinitions(List<UdaDefinition> udaDefinitions) {
        this.udaDefinitions = udaDefinitions;
    }

    public List<UdaDefinition> getUdaDefinitions() {
        return udaDefinitions;
    }

    public Set<Long> getUdaDefinitionKeysWithTargetType(UdaTargetType type) {
        List<UdaDefinition> definitions = getUdaDefinitions();
        Set<Long> result = new HashSet<>();
        for (UdaDefinition def : definitions) {
            if (def.getTargetType() == type) {
                result.add(Long.valueOf(def.getKey()));
            }
        }
        return result;
    }

    /**
     * Sets the domicile country for this organization. A supplier may restrict
     * the list of supported countries this organization can choose from.
     *
     * @param country
     */
    public void setDomicileCountry(SupportedCountry country) {
        domicileCountry = country;
    }

    /**
     * Returns the domicile of this organization.
     *
     * @return String The country code in ISO 3166.
     */
    public String getDomicileCountryCode() {
        if (domicileCountry == null) {
            return null;
        }
        return domicileCountry.getCountryISOCode();
    }

    /**
     * Returns the domicile country for this organization.
     *
     * @return OrganizationToCountry
     */
    public SupportedCountry getDomicileCountry() {
        return domicileCountry;
    }

    /**
     * Returns the list of OrganizationToCountry domain objects.
     *
     * @return List<OrganizationToCountry>
     */
    public List<OrganizationToCountry> getOrganizationToCountries() {
        return organizationToCountries;
    }

    /**
     * Returns the list of country codes that this organization supports.
     *
     * @return List<String>
     */
    public List<String> getSupportedCountryCodes() {
        List<String> result = new ArrayList<>();
        for (OrganizationToCountry orgToCountry : organizationToCountries) {
            result.add(orgToCountry.getCode());
        }
        return result;
    }

    /**
     * Adds the given country to the list of supported countries.
     *
     * @param country
     *            SupportedCountry to be added.
     */
    public void setSupportedCountry(SupportedCountry country) {
        if (!isCountrySupported(country.getCountryISOCode())) {
            OrganizationToCountry orgToCountry = new OrganizationToCountry();
            orgToCountry.setOrganization(this);
            orgToCountry.setSupportedCountry(country);
            organizationToCountries.add(orgToCountry);
        }
    }

    /**
     * Returns true if the given country code is supported by this organization.
     *
     * @param countryCode
     *            The country code in ISO 3166.
     * @return boolean
     */
    public boolean isCountrySupported(String countryCode) {
        return getOrganizationToCountry(countryCode) != null;
    }

    /**
     * Returns the OrganizationToCountry object for the given country code.
     *
     * @param countryCode
     *            The country code in ISO 3166.
     * @return OrganizationToCountry
     */
    public OrganizationToCountry getOrganizationToCountry(String countryCode) {
        for (OrganizationToCountry country : organizationToCountries) {
            if (country.getCode().equalsIgnoreCase(countryCode)) {
                return country;
            }
        }
        return null;
    }

    /**
     * Sets the defined VAT rates of the organization.
     *
     * @param vatRates
     *            The VAT rates to set.
     */
    public void setDefinedVatRates(List<VatRate> vatRates) {
        this.definedVatRates = vatRates;
    }

    /**
     * Returns the list of VAT rates that are defined from the organization.
     *
     * @return the list of VAT rates that are defined from the organization.
     */
    public List<VatRate> getDefinedVatRates() {
        return definedVatRates;
    }

    public void setSources(List<OrganizationReference> sources) {
        this.sources = sources;
    }

    public List<OrganizationReference> getSources() {
        return sources;
    }

    public void setTargets(List<OrganizationReference> targets) {
        this.targets = targets;
    }

    public List<OrganizationReference> getTargets() {
        return targets;
    }

    public void setMarketplaces(List<Marketplace> marketplaces) {
        this.marketplaces = marketplaces;
    }

    public List<Marketplace> getMarketplaces() {
        return marketplaces;
    }

    /**
     * Returns the referenced source organization for the given referenced type.
     *
     * @param orgRefType
     *            The reference type requested.
     * @return The organization references.
     */
    public List<OrganizationReference> getSourcesForType(
            OrganizationReferenceType orgRefType) {
        List<OrganizationReference> refsToSource = getSources();
        List<OrganizationReference> result = new ArrayList<>();
        for (OrganizationReference currentRef : refsToSource) {
            if (currentRef.getReferenceType() == orgRefType) {
                result.add(currentRef);
            }
        }
        return result;
    }

    public List<BillingContact> getBillingContacts() {
        return billingContacts;
    }

    public void setBillingContacts(List<BillingContact> billingContacts) {
        this.billingContacts = billingContacts;
    }

    /**
     * Evaluates the organization's subscriptions and returns those, that have
     * the specified status and that use the specified payment type.
     *
     * @param states
     *            The status set of the subscription.
     * @param paymentType
     *            The payment type that has to be checked for.
     * @return The subscriptions matching the conditions.
     */
    public List<Subscription> getSubscriptionsForStateAndPaymentType(
            Set<SubscriptionStatus> states, String paymentType) {
        List<Subscription> result = new ArrayList<>();
        List<Subscription> subs = getSubscriptions();
        for (Subscription subscription : subs) {
            if (states.contains(subscription.getStatus())
                    && subscription.getPaymentInfo() != null
                    && subscription.getPaymentInfo().getPaymentType()
                            .getPaymentTypeId().equals(paymentType)) {
                result.add(subscription);
            }
        }
        return result;
    }

    /**
     * Returns a list of all usable subscriptions for the given product. A
     * subscription is considered usable if a user can eventually subscribe to
     * it.
     */
    public List<Subscription> getUsableSubscriptionsForProduct(
            Product template) {
        if (template.isCopy()) {
            throw new IllegalArgumentException("Only templates allowed");
        }

        List<Subscription> result = new ArrayList<>();
        for (Subscription subscription : getUsableSubscriptions()) {
            // A product copy for a subscription to a broker/reseller product
            // refers to the resale product copy, not to the product template!
            if (subscription.getProduct().getProductTemplate()
                    .equals(template)) {
                result.add(subscription);
            }
        }

        return result;
    }

    /**
     * Returns TRUE if this organization is acting on behalf of the given
     * organization.
     */
    public boolean isActingOnBehalf(Organization customer) {
        for (OrganizationReference ref : customer.getSourcesForType(
                OrganizationReferenceType.ON_BEHALF_ACTING)) {
            if (ref.getSource().equals(this)) {
                return true;
            }
        }
        return false;
    }

    /**
     * @return a list of acting on behalf users of the customer organization.
     */
    public List<PlatformUser> getOnBehalfUsersFor(Organization customer) {
        List<PlatformUser> userList = getOnBehalfUsers(customer);
        filterOnBehalfUserList(userList);
        return userList;
    }

    private List<PlatformUser> getOnBehalfUsers(Organization customer) {
        List<PlatformUser> userList = new ArrayList<>();
        for (PlatformUser user : customer.getPlatformUsers()) {
            if (user.isOnBehalfUser()) {
                userList.add(user);
            }
        }
        return userList;
    }

    /**
     * Filter all user which are not belonging to the customer organization.
     *
     * @param userList
     *            the user list to filter, could contain user from other
     *            organizations
     */
    private void filterOnBehalfUserList(List<PlatformUser> userList) {
        Iterator<PlatformUser> iterator = userList.iterator();
        while (iterator.hasNext()) {
            PlatformUser onbehalfUser = iterator.next();
            if (!getPlatformUsers()
                    .contains(onbehalfUser.getMaster().getMasterUser())) {
                iterator.remove();
            }

        }
    }

    public void setPaymentInfos(List<PaymentInfo> paymentInfos) {
        this.paymentInfos = paymentInfos;
    }

    public List<PaymentInfo> getPaymentInfos() {
        return paymentInfos;
    }

    /**
     * Determines if the current organization may allow its customers to use the
     * specified payment type.
     *
     * @param type
     *            The payment type to check for.
     * @return <code>true</code> in case the type is supported,
     *         <code>false</code> otherwise.
     */
    public boolean canPermitPaymentType(String type) {
        for (OrganizationRefToPaymentType ref : getPaymentTypes(false,
                OrganizationRoleType.SUPPLIER,
                OrganizationRoleType.PLATFORM_OPERATOR.name())) {
            if (ref.getPaymentType().getPaymentTypeId().equals(type)) {
                return true;
            }
        }
        return false;
    }

    public void setMarketplaceToOrganizations(
            List<MarketplaceToOrganization> marketplaceToOrganizations) {
        this.marketplaceToOrganizations = marketplaceToOrganizations;
    }

    public List<MarketplaceToOrganization> getMarketplaceToOrganizations() {
        return marketplaceToOrganizations;
    }

    public void setPspAccounts(List<PSPAccount> pspAccounts) {
        this.pspAccounts = pspAccounts;
    }

    public List<PSPAccount> getPspAccounts() {
        return pspAccounts;
    }

    /**
     * Returns the PSP account registered for the organization which refers to
     * the specified PSP.
     *
     * @param psp
     *            The PSP to find the account for.
     * @return The registered PSP account or <code>null</code> if none exists.
     */
    public PSPAccount getPspAccountForPsp(PSP psp) {
        for (PSPAccount account : pspAccounts) {
            if (account.getPsp().equals(psp)) {
                return account;
            }
        }
        return null;
    }

    @Override
    public List<LocalizedObjectTypes> getLocalizedObjectTypes() {
        return LOCALIZATION_TYPES;
    }

    /**
     * Retrieves the udaDefinitions that will be readable by the specify role
     *
     * @param role
     * @return list of udaDefinitions
     */
    public List<UdaDefinition> getReadableUdaDefinitions(
            OrganizationRoleType role) {
        // get the list of defintions
        List<UdaDefinition> definitions = getUdaDefinitions();
        // check which definition is readable by passed role (by configuration
        // type)
        List<UdaDefinition> result = new ArrayList<>();
        for (UdaDefinition def : definitions) {
            if (def.getConfigurationType().canRead(role)) {
                result.add(def);
            }
        }
        // return the filtered list
        return result;

    }

    public List<UdaDefinition> getMandatoryUdaDefinitions() {
        // get the list of defintions
        List<UdaDefinition> definitions = getUdaDefinitions();
        // get all the mandatory uda definitions
        List<UdaDefinition> result = new ArrayList<>();
        for (UdaDefinition def : definitions) {
            if (def.getConfigurationType().isMandatory()) {
                result.add(def);
            }
        }
        // return the filtered list
        return result;
    }

    public OrganizationRoleType getVendorRoleForPaymentConfiguration() {
        OrganizationRoleType role = null;
        Set<OrganizationRoleType> types = getGrantedRoleTypes();
        if (types.contains(OrganizationRoleType.SUPPLIER)) {
            role = OrganizationRoleType.SUPPLIER;
        } else if (getGrantedRoleTypes()
                .contains(OrganizationRoleType.RESELLER)) {
            role = OrganizationRoleType.RESELLER;
        }
        return role;
    }

    /**
     * Returns the reference to the passed {@link Organization} of the passed
     * {@link OrganizationReferenceType} or <code>null</code> if it doesn't
     * exist.
     *
     * @param customer
     *            the customer {@link Organization}
     * @param type
     *            the required {@link OrganizationReferenceType}
     * @return the {@link OrganizationReference} ore <code>null</code>
     */
    public OrganizationReference getCustomerReference(Organization customer,
            OrganizationReferenceType type) {
        List<OrganizationReference> list = getTargets();
        for (OrganizationReference ref : list) {
            if (ref.getReferenceType() == type && ref.getTarget() == customer) {
                return ref;
            }
        }
        return null;
    }

    public void setCutOffDay(int cutOffDay) {
        dataContainer.setCutOffDay(cutOffDay);
    }

    public int getCutOffDay() {
        return dataContainer.getCutOffDay();
    }

    public RevenueShareModel getOperatorPriceModel() {
        return operatorPriceModel;
    }

    public void setOperatorPriceModel(RevenueShareModel operatorPriceModel) {
        this.operatorPriceModel = operatorPriceModel;
    }

    public List<UserGroup> getUserGroups() {
        return userGroups;
    }

    public void setUserGroups(List<UserGroup> userGroups) {
        this.userGroups = userGroups;
    }

    public boolean hasAtLeastOneRole(OrganizationRoleType... roles) {
        for (OrganizationRoleType role : roles) {
            if (this.hasRole(role)) {
                return true;
            }
        }
        return false;
    }

    public List<MarketplaceAccess> getMarketplaceAccesses() {
        return marketplaceAccesses;
    }

    public void setMarketplaceAccesses(
            List<MarketplaceAccess> marketplaceAccesses) {
        this.marketplaceAccesses = marketplaceAccesses;
    }

    public Tenant getTenant() {
        return tenant;
    }

    public void setTenant(Tenant tenant) {
        this.tenant = tenant;
    }
}


text:
from distutils.core import setup

setup(
    name='crx-python-webdriver',
    version='0.2.1',
    author='carn1x',
    author_email='github.com/carn1x',
    packages=['crx_python_webdriver'],
    install_requires=[
        'selenium',
    ],
    url='https://github.com/carn1x/crx-python-webdriver',
    license='MIT License, see LICENCE.txt',
    description='Selenium WebDriver framework providing a boilerplate and encouraged design pattern to run on top of' \
                'the WebDriver python bindings.',
    long_description=open('README.md').read(),
    zip_safe=False,
)

redpajama_set_name: RedPajamaGithub


text:
if [ $# -eq 0 ] ; then
  /bin/echo "Usage: env.sh COMMANDS"
  /bin/echo "Calling env.sh without arguments is not supported anymore. Instead spawn a subshell and source a setup file manually."
  exit 1
fi

# source setup_cached.sh from same directory as this file
_CATKIN_SETUP_DIR=$(cd `dirname $0`;pwd)
. "$_CATKIN_SETUP_DIR/setup_cached.sh"
exec "$@"


text:
<!DOCTYPE html>

      <meta charset="utf-8">
      <title>Agency Parallax Responsive HTML5/CSS3 Template | FIFO THEMES</title>
      <meta name="description" content="Agency Parallax Responsive HTML5/CSS3 Template from FIFOTHEMES.COM">
      <meta name="author" content="FIFOTHEMES.COM">

      <meta name="viewport" content="width=device-width, initial-scale=1.0">

      <link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700' rel='stylesheet' type='text/css'>
      <link href='http://fonts.googleapis.com/css?family=Raleway:400,500,600,700' rel='stylesheet' type='text/css'>
      <link href='http://fonts.googleapis.com/css?family=Pacifico' rel='stylesheet' type='text/css'>
      <link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Tangerine" />

      <link rel="stylesheet" href="css/bootstrap.min.css">
      <link rel="stylesheet" href="css/bootstrap-theme.min.css">
      <link rel="stylesheet" href="css/team-member.css" media="screen">
      <link rel="stylesheet" href="css/fonts/font-awesome/css/font-awesome.css">
      <link rel="stylesheet" href="css/animations.css" media="screen">
      <link rel="stylesheet" href="css/prettyPhoto.css" media="screen">

      <link rel="stylesheet" href="css/style.css">
      <link rel="stylesheet" href="css/global.css">

      <link rel="stylesheet" href="css/colors/blue.css" class="colors">

      <link rel="shortcut icon" href="img/ico/favicon.ico">
      <link rel="apple-touch-icon" href="img/ico/apple-touch-icon.png">
      <link rel="apple-touch-icon" sizes="72x72" href="img/ico/apple-touch-icon-72.png">
      <link rel="apple-touch-icon" sizes="114x114" href="img/ico/apple-touch-icon-114.png">
      <link rel="apple-touch-icon" sizes="144x144" href="img/ico/apple-touch-icon-144.png">

                                                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#menu">

                                                </button>

Home

About Us

Portfolio

Services

Clients

Pricing

                                                                        Blog

Blog

Blog Large

Single Page

Contact

The Blog

Blog post title

                                                                        November
                                                                        23,
                                                                        2014

                                                                        John Doe

                                                                        Web Design,
                                                                        Branding

                                                                        3 comments

                                                                  Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

                                                            Read More

Blog post title

                                                                        October
                                                                        23,
                                                                        2014

                                                                        John Doe

                                                                        Web Design,
                                                                        Branding

                                                                        3 comments

                                                                  Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

                                                            Read More

Blog post title

                                                                        September
                                                                        23,
                                                                        2014

                                                                        John Doe

                                                                        Web Design,
                                                                        Branding

                                                                        3 comments

                                                                  Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

                                                            Read More

«

1

2

3

4

5

»

                                                      <input type="text" value="Search..." onfocus="if(this.value=='Search...')this.value='';" onblur="if(this.value=='')this.value='Search...';" class="search-input form-control">

                                                            <button type="submit" class="subscribe-btn btn"></button>

Popular

Recent

Comments

Lorem Ipsum is simply dummy text.

                                                                              27 February 2014

Lorem Ipsum is simply dummy text.

                                                                              1 March 2013

Lorem Ipsum is simply dummy text.

                                                                              27 February 2014

Lorem Ipsum is simply dummy text.

                                                                              1 March 2013

Lorem Ipsum is simply dummy text.

                                                                              by wptuts+

Lorem Ipsum is simply dummy text.

                                                                              by wptuts+

Testimonials

                                                                                Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type.

                                                                                Monica Sing FIFO Themes

                                                                                Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type.

                                                                                Monzurul Haque FIFO Themes

                                                                                Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type.

                                                                                Carol Johansen FIFO Themes

Categories

Web Design

Graphic Design

Illustration

Logo Design

Wordpress Themes

Advertisement

 © 2014 FifoThemes


text:
#ifndef _OMAP24XX_I2C_H_
#define _OMAP24XX_I2C_H_

#define I2C_BASE1		0x48070000
#define I2C_BASE2               0x48072000 /* nothing hooked up on h4 */

#define I2C_DEFAULT_BASE	I2C_BASE1

struct i2c {
	unsigned short rev;	/* 0x00 */
	unsigned short res1;
	unsigned short ie;	/* 0x04 */
	unsigned short res2;
	unsigned short stat;	/* 0x08 */
	unsigned short res3;
	unsigned short iv;	/* 0x0C */
	unsigned short res4;
	unsigned short syss;	/* 0x10 */
	unsigned short res4p1;
	unsigned short buf;	/* 0x14 */
	unsigned short res5;
	unsigned short cnt;	/* 0x18 */
	unsigned short res6;
	unsigned short data;	/* 0x1C */
	unsigned short res7;
	unsigned short sysc;	/* 0x20 */
	unsigned short res8;
	unsigned short con;	/* 0x24 */
	unsigned short res9;
	unsigned short oa;	/* 0x28 */
	unsigned short res10;
	unsigned short sa;	/* 0x2C */
	unsigned short res11;
	unsigned short psc;	/* 0x30 */
	unsigned short res12;
	unsigned short scll;	/* 0x34 */
	unsigned short res13;
	unsigned short sclh;	/* 0x38 */
	unsigned short res14;
	unsigned short systest;	/* 0x3c */
	unsigned short res15;
};

#define I2C_BUS_MAX	2

#endif


text:
{{{
  "title": "Set Server Disks",
  "date": "02-11-2015",
  "author": "Bryan Friedman",
  "attachments": []
}}}

Changes (adds or removes) disks on an existing server. Calls to this operation must include a token acquired from the authentication endpoint. See the [Login API](../Authentication/login.md) for information on acquiring this token.

### When to Use It

Use this API operation when you want to change the disks on an existing server.

## URL

### Structure

    PATCH https://api.ctl.io/v2/servers/{accountAlias}/{serverId}

### Example

    PATCH https://api.ctl.io/v2/servers/ACCT/WA1ACCTSERV0101

## Request

### URI Parameters

| Name | Type | Description | Req. |
| --- | --- | --- | --- |
| AccountAlias | string | Short code for a particular account | Yes |
| ServerId | string | ID of the server with the disk configuration to update. Retrieved from query to containing group, or by looking at the URL when viewing a server in the Control Portal. | Yes |

### Content Properties

| Name | Type | Description | Req. |
| --- | --- | --- | --- |
| patchOperation | array | A list of properties, values, and the operations to perform with them for the server. | Yes |

### PatchOperation Definition

| Name | Type | Description |
| --- | --- | --- |
| op | string | The operation to perform on a given property of the server. In this case, the value must be "set" for setting the disk configuration. |
| member | string | The property of the server to perform the operation on. In this case, the value must be "disks" for setting the disks. |
| value | array | A list of information for _all disks_ to be on the server including type (raw or partition), size, and path.

_Note: You must specify the complete list of disks to be on the server. If you want to add or resize a disk, specify all existing disks/sizes along with a new entry for the disk to add or the new size of an existing disk. To delete a disk, just specify all the disks that should remain. (You can get existing disk info by using the [Get Server](get-server.md) call to see all the details of the server.)_ |

### Examples

#### JSON

    [
       {
          "op":"set",
          "member":"disks",
          "value":[
             {
               "diskId":"0:0",
               "sizeGB":1
             },
             {
               "diskId":"0:1",
               "sizeGB":2
             },
             {
               "diskId":"0:2",
               "sizeGB":16
             },
             {
               "path":"/extra",
               "sizeGB":"20",
               "type":"partitioned"
             }
          ]
       }
    ]

## Response

The response is a link to the [Get Status](../Queue/get-status.md) operation so the asynchronous job can be tracked. Once successfully completed, the server configuration will be changed as specified.

### Entity Definition

|Name|Type|Value|Description|
|---|---|---|---|
|rel|string|status|The link type|
|href|string|/v2/operations/[ALIAS]/status/[ID]|Address of the job in the queue|
|id|string|[ID]|The identifier of the job in queue. Can be passed to [Get Status](../Queue/get-status.md) call to retrieve status of job.|

### Examples

#### JSON

    {
      "rel":"status",
      "href":"/v2/operations/alias/status/wa1-12345",
      "id":"wa1-12345"
    }


text:
package main

import "github.com/dh1tw/remoteAudio/cmd"

func main() {
	cmd.Execute()
}


text:
<?php
/**
 * @author @jenschude <jens.schulze@commercetools.de>
 */

namespace Commercetools\Core\IntegrationTests\Channel;

use Commercetools\Core\Builder\Request\RequestBuilder;
use Commercetools\Core\IntegrationTests\ApiTestCase;
use Commercetools\Core\IntegrationTests\Type\TypeFixture;
use Commercetools\Core\Model\Channel\Channel;
use Commercetools\Core\Model\Channel\ChannelDraft;
use Commercetools\Core\Model\Channel\ChannelRole;
use Commercetools\Core\Model\Common\Address;
use Commercetools\Core\Model\Common\GeoPoint;
use Commercetools\Core\Model\Common\LocalizedString;
use Commercetools\Core\Model\CustomField\CustomFieldObjectDraft;
use Commercetools\Core\Model\CustomField\FieldContainer;
use Commercetools\Core\Model\Type\Type;
use Commercetools\Core\Model\Type\TypeDraft;
use Commercetools\Core\Request\Channels\Command\ChannelAddRolesAction;
use Commercetools\Core\Request\Channels\Command\ChannelChangeDescriptionAction;
use Commercetools\Core\Request\Channels\Command\ChannelChangeKeyAction;
use Commercetools\Core\Request\Channels\Command\ChannelChangeNameAction;
use Commercetools\Core\Request\Channels\Command\ChannelRemoveRolesAction;
use Commercetools\Core\Request\Channels\Command\ChannelSetAddressAction;
use Commercetools\Core\Request\Channels\Command\ChannelSetAddressCustomFieldAction;
use Commercetools\Core\Request\Channels\Command\ChannelSetAddressCustomTypeAction;
use Commercetools\Core\Request\Channels\Command\ChannelSetGeoLocation;
use Commercetools\Core\Request\Channels\Command\ChannelSetRolesAction;
use Commercetools\Core\Request\CustomField\Command\SetCustomFieldAction;
use Commercetools\Core\Request\CustomField\Command\SetCustomTypeAction;

class ChannelUpdateRequestTest extends ApiTestCase
{
    public function testChangeName()
    {
        $client = $this->getApiClient();

        ChannelFixture::withUpdateableChannel(
            $client,
            function (Channel $channel) use ($client) {
                $name = 'new name-' . ChannelFixture::uniqueChannelString();

                $request = RequestBuilder::of()->channels()->update($channel)->addAction(
                    ChannelChangeNameAction::ofName(
                        LocalizedString::ofLangAndText('en', $name)
                    )
                );
                $response = $this->execute($client, $request);
                $result = $request->mapFromResponse($response);

                $this->assertInstanceOf(Channel::class, $result);
                $this->assertSame($name, $result->getName()->en);
                $this->assertNotSame($channel->getVersion(), $result->getVersion());

                return $result;
            }
        );
    }

    public function testChangeDescription()
    {
        $client = $this->getApiClient();

        ChannelFixture::withUpdateableChannel(
            $client,
            function (Channel $channel) use ($client) {
                $description = 'new description-' . ChannelFixture::uniqueChannelString();

                $request = RequestBuilder::of()->channels()->update($channel)
                    ->addAction(
                        ChannelChangeDescriptionAction::ofDescription(
                            LocalizedString::ofLangAndText('en', $description)
                        )
                    );
                $response = $this->execute($client, $request);
                $result = $request->mapFromResponse($response);

                $this->assertInstanceOf(Channel::class, $result);
                $this->assertSame($description, $result->getDescription()->en);
                $this->assertNotSame($channel->getVersion(), $result->getVersion());

                return $result;
            }
        );
    }

    public function testChangeKey()
    {
        $client = $this->getApiClient();

        ChannelFixture::withUpdateableChannel(
            $client,
            function (Channel $channel) use ($client) {
                $key = 'new key-' . ChannelFixture::uniqueChannelString();

                $request = RequestBuilder::of()->channels()->update($channel)
                    ->addAction(
                        ChannelChangeKeyAction::ofKey($key)
                    );
                $response = $this->execute($client, $request);
                $result = $request->mapFromResponse($response);

                $this->assertInstanceOf(Channel::class, $result);
                $this->assertSame($key, $result->getKey());
                $this->assertNotSame($channel->getVersion(), $result->getVersion());

                return $result;
            }
        );
    }

    public function testSetAddress()
    {
        $client = $this->getApiClient();

        ChannelFixture::withUpdateableDraftChannel(
            $client,
            function (ChannelDraft $draft) {
                return $draft->setAddress(Address::of()->setCountry('US'));
            },
            function (Channel $channel) use ($client) {
                $this->assertSame('US', $channel->getAddress()->getCountry());

                $address = Address::of()->setCountry('DE');

                $request = RequestBuilder::of()->channels()->update($channel)
                    ->addAction(
                        ChannelSetAddressAction::of()->setAddress($address)
                    );
                $response = $this->execute($client, $request);
                $result = $request->mapFromResponse($response);

                $this->assertInstanceOf(Channel::class, $result);
                $this->assertSame('DE', $result->getAddress()->getCountry());
                $this->assertNotSame($channel->getVersion(), $result->getVersion());

                return $result;
            }
        );
    }

    public function testAddRoles()
    {
        $client = $this->getApiClient();

        ChannelFixture::withUpdateableChannel(
            $client,
            function (Channel $channel) use ($client) {
                $roles = [ChannelRole::PRIMARY];

                $request = RequestBuilder::of()->channels()->update($channel)
                    ->addAction(
                        ChannelAddRolesAction::ofRoles($roles)
                    );
                $response = $this->execute($client, $request);
                $result = $request->mapFromResponse($response);

                $this->assertInstanceOf(Channel::class, $result);
                $this->assertSame([ChannelRole::INVENTORY_SUPPLY, ChannelRole::PRIMARY], $result->getRoles());
                $this->assertNotSame($channel->getVersion(), $result->getVersion());

                return $result;
            }
        );
    }

    public function testRemoveRoles()
    {
        $client = $this->getApiClient();

        ChannelFixture::withUpdateableDraftChannel(
            $client,
            function (ChannelDraft $draft) {
                return $draft->setRoles([ChannelRole::INVENTORY_SUPPLY, ChannelRole::PRIMARY]);
            },
            function (Channel $channel) use ($client) {
                $roles = [ChannelRole::INVENTORY_SUPPLY];

                $request = RequestBuilder::of()->channels()->update($channel)
                    ->addAction(
                        ChannelRemoveRolesAction::ofRoles($roles)
                    );
                $response = $this->execute($client, $request);
                $result = $request->mapFromResponse($response);

                $this->assertInstanceOf(Channel::class, $result);
                $this->assertSame([ChannelRole::PRIMARY], $result->getRoles());
                $this->assertNotSame($channel->getVersion(), $result->getVersion());

                return $result;
            }
        );
    }

    public function testSetRoles()
    {
        $client = $this->getApiClient();

        ChannelFixture::withUpdateableChannel(
            $client,
            function (Channel $channel) use ($client) {
                $this->assertSame([ChannelRole::INVENTORY_SUPPLY], $channel->getRoles());

                $roles = [ChannelRole::PRIMARY, ChannelRole::PRODUCT_DISTRIBUTION];

                $request = RequestBuilder::of()->channels()->update($channel)
                    ->addAction(
                        ChannelSetRolesAction::ofRoles($roles)
                    );
                $response = $this->execute($client, $request);
                $result = $request->mapFromResponse($response);

                $this->assertInstanceOf(Channel::class, $result);
                $this->assertSame($roles, $result->getRoles());
                $this->assertNotSame($channel->getVersion(), $result->getVersion());

                return $result;
            }
        );
    }

    public function testChannelCustom()
    {
        $client = $this->getApiClient();

        TypeFixture::withDraftType(
            $client,
            function (TypeDraft $TypeDraft) {
                return $TypeDraft
                    ->setKey('channel_custom_test')
                    ->setResourceTypeIds(['channel']);
            },
            function (Type $type) use ($client) {
                ChannelFixture::withUpdateableDraftChannel(
                    $client,
                    function (ChannelDraft $channelDraft) use ($type) {
                        return $channelDraft->setCustom(
                            CustomFieldObjectDraft::ofTypeKeyAndFields(
                                $type->getKey(),
                                FieldContainer::of()->set('testField', 'value')
                            )
                        );
                    },
                    function (Channel $channel) use ($client, $type) {
                        $this->assertInstanceOf(Channel::class, $channel);
                        $this->assertSame('value', $channel->getCustom()->getFields()->getTestField());

                        $field = 'testField';
                        $newValue = 'new value';

                        $request = RequestBuilder::of()->channels()->update($channel)
                            ->addAction(
                                SetCustomTypeAction::ofTypeKey($type->getKey())
                                    ->setFields(
                                        FieldContainer::of()
                                            ->set($field, $newValue)
                                    )
                            );
                        $response = $this->execute($client, $request);
                        $result = $request->mapFromResponse($response);

                        $this->assertInstanceOf(Channel::class, $result);
                        $this->assertSame($newValue, $result->getCustom()->getFields()->getTestField());

                        $newValue2 = 'new value 2';

                        $request = RequestBuilder::of()->channels()->update($result)
                            ->addAction(
                                SetCustomFieldAction::ofName($field)
                                    ->setValue('' . $newValue2 . '')
                            );
                        $response = $this->execute($client, $request);
                        $result = $request->mapFromResponse($response);

                        $this->assertInstanceOf(Channel::class, $result);
                        $this->assertSame($newValue2, $result->getCustom()->getFields()->getTestField());

                        return $result;
                    }
                );
            }
        );
    }

    public function testSetGeoLocation()
    {
        $client = $this->getApiClient();
        $brandenburgerTor = [13.37770, 52.51627];
        $friedrichstadtPalast = [13.38881, 52.52394];

        ChannelFixture::withUpdateableDraftChannel(
            $client,
            function (ChannelDraft $draft) use ($brandenburgerTor) {
                return $draft->setGeoLocation(GeoPoint::of()->setCoordinates($brandenburgerTor));
            },
            function (Channel $channel) use ($client, $friedrichstadtPalast) {
                $request = RequestBuilder::of()->channels()->update($channel)
                    ->addAction(
                        ChannelSetGeoLocation::of()->setGeoLocation(GeoPoint::of()
                            ->setCoordinates($friedrichstadtPalast))
                    );
                $response = $this->execute($client, $request);
                $result = $request->mapFromResponse($response);

                $this->assertInstanceOf(Channel::class, $result);
                $this->assertSame($friedrichstadtPalast, $result->getGeoLocation()->getCoordinates());
                $this->assertNotSame($channel->getVersion(), $result->getVersion());

                return $result;
            }
        );
    }

    public function testSetAddressCustom()
    {
        $client = $this->getApiClient();

        TypeFixture::withDraftType(
            $client,
            function (TypeDraft $typeDraft) {
                return $typeDraft->setKey('address-set-field-on-channel')
                    ->setResourceTypeIds(['address']);
            },
            function (Type $type) use ($client) {
                ChannelFixture::withUpdateableDraftChannel(
                    $client,
                    function (ChannelDraft $channelDraft) {
                        return $channelDraft->setAddress(
                            Address::of()->setFirstName('test-' . ChannelFixture::uniqueChannelString() . '@example.com')
                                ->setCountry('DE')
                                ->setCustom(
                                    CustomFieldObjectDraft::ofTypeKey('address-set-field-on-channel')
                                        ->setFields(FieldContainer::of()->set('testField', 'value'))
                                )
                        );
                    },
                    function (Channel $channel) use ($client, $type) {
                        $this->assertInstanceOf(Channel::class, $channel);
                        $this->assertSame('value', $channel->getAddress()->getCustom()->getFields()->getTestField());

                        $field = 'testField';
                        $newValue = 'new value';

                        $request = RequestBuilder::of()->channels()->update($channel)
                            ->addAction(
                                ChannelSetAddressCustomTypeAction::ofTypeKey($type->getKey())
                                    ->setFields(FieldContainer::of()
                                        ->set($field, $newValue))
                            );
                        $response = $this->execute($client, $request);
                        $result = $request->mapFromResponse($response);

                        $this->assertInstanceOf(Channel::class, $result);
                        $this->assertSame($newValue, $result->getAddress()->getCustom()->getFields()->getTestField());

                        $newValue2 = 'new value 2';

                        $request = RequestBuilder::of()->channels()->update($result)
                            ->addAction(
                                ChannelSetAddressCustomFieldAction::ofName($field)
                                    ->setValue('' . $newValue2 . '')
                            );
                        $response = $this->execute($client, $request);
                        $result = $request->mapFromResponse($response);

                        $this->assertInstanceOf(Channel::class, $result);
                        $this->assertSame($newValue2, $result->getAddress()->getCustom()->getFields()->getTestField());

                        return $result;
                    }
                );
            }
        );
    }
}