protected Response putOrganization ( String domainName , final UriInfo info , MediaType responseType ) { if ( domainName == null ) { return status ( BAD_REQUEST ) . entity ( MSG_EMPTY_DOMAIN_NAME ) . build ( ) ; } else { //Character verification if ( ! pattern . matcher ( domainName ) . matches ( ) ) { return status ( BAD_REQUEST ) . entity ( MSG_INVALID_DOMAIN_NAME_PATTERN ) . build ( ) ; } Organization organization ; if ( dnsProvisioningManager == null ) { //Check if domain_name does not already taken inside restcomm by an organization. organization = organizationsDao . getOrganizationByDomainName ( domainName ) ; if ( organization != null ) { return status ( CONFLICT ) . entity ( MSG_DOMAIN_NAME_NOT_AVAILABLE ) . build ( ) ; } logger . warn ( "No DNS provisioning Manager is configured, restcomm will not make any queries to DNS server." ) ; organization = new Organization ( Sid . generate ( Sid . Type . ORGANIZATION ) , domainName , DateTime . now ( ) , DateTime . now ( ) , Organization . Status . ACTIVE ) ; organizationsDao . addOrganization ( organization ) ; } else { //for example hosted zone id of domain restcomm.com or others. if not provided then default will be used as per configuration String hostedZoneId = info . getQueryParameters ( ) . getFirst ( "HostedZoneId" ) ; //Check if domain_name does not already taken inside restcomm by an organization. String completeDomainName = dnsProvisioningManager . getCompleteDomainName ( domainName , hostedZoneId ) ; organization = organizationsDao . getOrganizationByDomainName ( completeDomainName ) ; if ( organization != null ) { return status ( CONFLICT ) . entity ( MSG_DOMAIN_NAME_NOT_AVAILABLE ) . build ( ) ; } //check if domain name already exists on dns side or not if ( dnsProvisioningManager . doesResourceRecordAlreadyExists ( domainName , hostedZoneId ) ) { return status ( CONFLICT ) . entity ( MSG_DOMAIN_NAME_NOT_AVAILABLE ) . build ( ) ; } if ( ! dnsProvisioningManager . createResourceRecord ( domainName , hostedZoneId ) ) { logger . error ( "could not create resource record on dns server" ) ; return status ( INTERNAL_SERVER_ERROR ) . build ( ) ; } else { organization = new Organization ( Sid . generate ( Sid . Type . ORGANIZATION ) , completeDomainName , DateTime . now ( ) , DateTime . now ( ) , Organization . Status . ACTIVE ) ; organizationsDao . addOrganization ( organization ) ; } } if ( APPLICATION_XML_TYPE . equals ( responseType ) ) { final RestCommResponse response = new RestCommResponse ( organization ) ; return ok ( xstream . toXML ( response ) , APPLICATION_XML ) . build ( ) ; } else if ( APPLICATION_JSON_TYPE . equals ( responseType ) ) { return ok ( gson . toJson ( organization ) , APPLICATION_JSON ) . build ( ) ; } else { return null ; } } }
putOrganization create new organization