Package org.wso2.carbon.governance.api.services.dataobjects

Examples of org.wso2.carbon.governance.api.services.dataobjects.Service


   
    ServiceBean[] serviceBeans = new ServiceBean[serviceIds.length];
    for (int i = 0; i < serviceIds.length; i++) {
      serviceBeans[i] = new ServiceBean();
      if (serviceIds[i] != null) {
        Service service = manager.getService(serviceIds[i]);
        serviceBeans[i].setWsdlBeans(populateWSDLBean(service.getAttachedWsdls()));
        serviceBeans[i].setSchemaBeans(populateSchemaBean(service.getAttachedSchemas()));
        serviceBeans[i].setPolicyBeans(populatePolicyBean(service.getAttachedPolicies()));
        serviceBeans[i].setId(service.getId());
        serviceBeans[i].setPath(service.getPath());
        serviceBeans[i].setqName(getName(service.getQName()));
      }
    }
    return serviceBeans;
  }
View Full Code Here


                if (contentBytes == null) {
                    throw new GovernanceException("Unable to read payload of governance artifact " +
                            "at path: " + artifactPath);
                }
                OMElement contentElement = buildOMElement(contentBytes);
                Service service = new Service(artifactId, contentElement);
                service.associateRegistry(registry);
                return service;
//            }
            /*else if (GovernanceConstants.PROCESS_MEDIA_TYPE.equals(
                    artifactResource.getMediaType())) {
                // it is a process
View Full Code Here

            } else {
                currentNamespace = CommonUtil.getServiceNamespace(serviceElement);
            }

            ServiceManager serviceManager = new ServiceManager(registry);
            Service service = serviceManager.newService(serviceElement);
            String lifeCycleName = service.getAttribute("serviceLifecycle_lifecycleName");

            String finalPath="";

            if ("Edit".equals(operation)) {
                // this is an edit operation, retrieve the old namespace and name

                String currentPath = "";
                if (serviceElement.getChildrenWithLocalName("newServicePath").hasNext()) {
                    Iterator OmElementIterator = serviceElement.getChildrenWithLocalName("newServicePath");

                    while (OmElementIterator.hasNext()) {
                        OMElement next = (OMElement) OmElementIterator.next();
                        currentPath = next.getText();
                        break;
                    }
                }else{
                    currentPath = registry.getRegistryContext().getServicePath() +
                            CommonUtil.derivePathFragmentFromNamespace(currentNamespace) + currentName;
                }
                currentPath = RegistryUtils.getRelativePathToOriginal(currentPath,
                        RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH);
                finalPath = new String(currentPath);
                String version = service.getAttribute("overview_version");
                if (version == null ) {
                    currentPath = CommonUtil.computeServicePathWithVersion(currentPath, "1.0.0-SNAPSHOT");
                }else{
                    currentPath = CommonUtil.computeServicePathWithVersion(currentPath, version);
                }
                if (registry.resourceExists(currentPath)) {
                    GovernanceArtifact oldArtifact =
                            GovernanceUtils.retrieveGovernanceArtifactByPath(registry, currentPath);
                    if (!(oldArtifact instanceof Service)) {
                        String msg = "The updated path is occupied by a non-service. path: " +
                                currentPath + ".";
                        log.error(msg);
                        throw new Exception(msg);
                    }
                    // id is used to differentiate the service
                    String id = oldArtifact.getId();
                    service.setId(id);
                    serviceManager.updateService(service);
                    Resource serviceResource = registry.get(service.getPath());
                    String oldLifeCycleName = serviceResource.getProperty("registry.LC.name");
                    if (lifeCycleName == null) {
                        removeAspect(registry, service.getPath(), oldLifeCycleName);
                    }
                    if (lifeCycleName != null) {
                        if (oldLifeCycleName == null || !oldLifeCycleName.equals(lifeCycleName)) {
                            // if user select a different lifecycle for the service, first delete
                            // the previous one and then associate the new one.
                            removeAspect(registry, service.getPath(), oldLifeCycleName);
                            registry.associateAspect(service.getPath(), lifeCycleName);
                        }
                    }
                    return true;
                }
            }
            serviceManager.addService(service);
            if (lifeCycleName != null) {
                registry.associateAspect(service.getPath(), lifeCycleName);
            }
            /*if (!"".equals(finalPath)) {
                if(service.getPath().startsWith(RegistryConstants.PATH_SEPARATOR+ TRUNK)){
                    Association[] allAssociations = registry.getAllAssociations(finalPath);

View Full Code Here

        ServiceManager serviceManager = new ServiceManager(registry);

        for (GovernanceArtifact artifact: artifacts) {
            if (artifact instanceof Service) {
                // getting the service.
                Service service2 = (Service)artifact;
                serviceManager.removeService(service2.getId());
            }
        }       

        // now try to remove the endpoint
        endpointManager.removeEndpoint(endpoints[0].getId());
View Full Code Here

        assertTrue(true);
    }

    public void testAddServiceWithEndpoints() throws Exception {
        ServiceManager serviceManager = new ServiceManager(registry);
        Service service = serviceManager.newService(new QName("http://wso2.com/test/xxx", "myService"));

        service.addAttribute("endpoints_entry", ":http://endpoint1");
        service.addAttribute("endpoints_entry", "QA:http://endpoint2");

        serviceManager.addService(service);

        Endpoint[] endpoints = service.getAttachedEndpoints();
        assertEquals(2, endpoints.length);

        assertEquals("http://endpoint1", endpoints[0].getUrl());
        assertEquals(0, endpoints[0].getAttributeKeys().length);

        assertEquals("http://endpoint2", endpoints[1].getUrl());
        assertEquals(1, endpoints[1].getAttributeKeys().length);
        assertEquals("QA", endpoints[1].getAttribute(CommonConstants.ENDPOINT_ENVIRONMENT_ATTR));

        // now update the endpoints in the service
        service.setAttributes("endpoints_entry", new String[] {
                "Dev:http://endpoint3",
                "Production:http://endpoint4",
                "QA:http://endpoint2",
        });
        serviceManager.updateService(service);

        endpoints = service.getAttachedEndpoints();
        assertEquals(3, endpoints.length);


        assertEquals("http://endpoint3", endpoints[0].getUrl());
        assertEquals(1, endpoints[0].getAttributeKeys().length);
View Full Code Here

    }

    // add endpoints as attachments
    public void testAttachEndpointsToService() throws Exception {
        ServiceManager serviceManager = new ServiceManager(registry);
        Service service = serviceManager.newService(new QName("http://wso2.com/test234/xxxxx", "myServicxcde"));
        serviceManager.addService(service);

        EndpointManager endpointManager = new EndpointManager(registry);
        Endpoint ep1 = endpointManager.newEndpoint("http://endpoint1xx");
        endpointManager.addEndpoint(ep1);

        Endpoint ep2 = endpointManager.newEndpoint("http://endpoint2xx");
        ep2.setAttribute(CommonConstants.ENDPOINT_ENVIRONMENT_ATTR, "QA");
        endpointManager.addEndpoint(ep2);

        service.attachEndpoint(ep1);
        service.attachEndpoint(ep2);

        Endpoint[] endpoints = service.getAttachedEndpoints();
        assertEquals(2, endpoints.length);

        assertEquals("http://endpoint1xx", endpoints[0].getUrl());
        assertEquals(0, endpoints[0].getAttributeKeys().length);

        assertEquals("http://endpoint2xx", endpoints[1].getUrl());
        assertEquals(1, endpoints[1].getAttributeKeys().length);
        assertEquals("QA", endpoints[1].getAttribute(CommonConstants.ENDPOINT_ENVIRONMENT_ATTR));

        service.detachEndpoint(ep1.getId());
        endpoints = service.getAttachedEndpoints();
        assertEquals(1, endpoints.length);
       
        assertEquals("http://endpoint2xx", endpoints[0].getUrl());
        assertEquals(1, endpoints[0].getAttributeKeys().length);
        assertEquals("QA", endpoints[0].getAttribute(CommonConstants.ENDPOINT_ENVIRONMENT_ATTR));


        // now update the endpoints in the service
        service.setAttributes("endpoints_entry", new String[] {
                "Dev:http://endpoint3",
                "Production:http://endpoint4",
                "QA:http://endpoint2xx",
        });
        serviceManager.updateService(service);

        endpoints = service.getAttachedEndpoints();
        assertEquals(3, endpoints.length);


        assertEquals("http://endpoint3", endpoints[0].getUrl());
        assertEquals(1, endpoints[0].getAttributeKeys().length);
View Full Code Here

        assertEquals("QA", ep5.getAttribute(CommonConstants.ENDPOINT_ENVIRONMENT_ATTR));
    }

    public void testAssociatingEndpoints() throws Exception {
        ServiceManager serviceManager = new ServiceManager(registry);
        Service service = serviceManager.newService(new QName("http://done.ding/dong/doodo", "bangService343"));

        serviceManager.addService(service);

        EndpointManager endpointManager = new EndpointManager(registry);
        Endpoint endpoint = endpointManager.newEndpoint("http://dos.dis/doos/safdsf/ppeekk");
        endpointManager.addEndpoint(endpoint);
        service.attachEndpoint(endpoint);

        // retrieve the service
        Service service2 = serviceManager.getService(service.getId());
        Endpoint[] endpoints = service2.getAttachedEndpoints();
        assertEquals(1, endpoints.length);

        assertEquals(":" + endpoints[0].getUrl(), service2.getAttribute("endpoints_entry"));
    }
View Full Code Here

        fileInputStream.read(fileContents);

        OMElement contentElement = GovernanceUtils.buildOMElement(fileContents);

        ServiceManager serviceManager = new ServiceManager(registry);
        Service service = serviceManager.newService(contentElement);

        service.addAttribute("custom-attribute", "custom-value");
        serviceManager.addService(service);


        // so retrieve it back
        String serviceId = service.getId();
        Service newService = serviceManager.getService(serviceId);
        assertEquals(newService.getAttribute("custom-attribute")"custom-value");
        assertEquals(newService.getAttribute("endpoints_entry"),
                ":http://localhost:8080/axis2/services/BizService");

        // now we just add an endpoints
        WsdlManager wsdlManager = new WsdlManager(registry);
        Wsdl wsdl = wsdlManager.newWsdl("http://svn.wso2.org/repos/wso2/trunk/carbon/components/governance/org.wso2.carbon.governance.api/src/test/resources/test-resources/wsdl/MyChangedBizService.wsdl");
        wsdl.addAttribute("boom", "hahahaha");

        wsdlManager.addWsdl(wsdl);

        GovernanceArtifact[] artifacts = wsdl.getDependents();

        for (GovernanceArtifact artifact: artifacts) {
            if (artifact instanceof Service) {
                // getting the service.
                Service service2 = (Service)artifact;
                Endpoint[] endpoints = service2.getAttachedEndpoints();
                assertEquals(1, endpoints.length);
                assertEquals("http://localhost:8080/axis2/services/BizService-my-changes", endpoints[0].getUrl());
            }
        }
    }
View Full Code Here

    }

    // detach endpoints
    public void testDetachEndpointsToService() throws Exception {
        ServiceManager serviceManager = new ServiceManager(registry);
        Service service = serviceManager.newService(new QName("http://wso2.com/test234/xxxxx", "myServicxcde"));
        serviceManager.addService(service);

        EndpointManager endpointManager = new EndpointManager(registry);
        Endpoint ep1 = endpointManager.newEndpoint("http://endpoint1");
        endpointManager.addEndpoint(ep1);

        Endpoint ep2 = endpointManager.newEndpoint("http://endpoint2");
        ep2.setAttribute(CommonConstants.ENDPOINT_ENVIRONMENT_ATTR, "QA");
        endpointManager.addEndpoint(ep2);

        service.attachEndpoint(ep1);
        service.attachEndpoint(ep2);

        Endpoint[] endpoints = service.getAttachedEndpoints();
        assertEquals(2, endpoints.length);

        // get the updated service endpoints
        service = serviceManager.getService(service.getId());

        String[] endpointValues = service.getAttributes("endpoints_entry");

        assertEquals(2, endpointValues.length);
    }
View Full Code Here

    }

    // add non http endpoints as attachments
    public void testNonHttpEndpointsToService() throws Exception {
        ServiceManager serviceManager = new ServiceManager(registry);
        Service service = serviceManager.newService(new QName("http://wso2.com/doadf/spidf", "myServisdfcxcde"));
        serviceManager.addService(service);

        EndpointManager endpointManager = new EndpointManager(registry);
        Endpoint ep1 = endpointManager.newEndpoint("jms:/Service1");
        endpointManager.addEndpoint(ep1);

        Endpoint ep2 = endpointManager.newEndpoint("jms:/Service2");
        ep2.setAttribute(CommonConstants.ENDPOINT_ENVIRONMENT_ATTR, "QA");
        endpointManager.addEndpoint(ep2);

        service.attachEndpoint(ep1);
        service.attachEndpoint(ep2);

        Endpoint[] endpoints = service.getAttachedEndpoints();
        assertEquals(2, endpoints.length);

        // get the updated service endpoints
        service = serviceManager.getService(service.getId());

        String[] endpointValues = service.getAttributes("endpoints_entry");

        assertEquals(2, endpointValues.length);
    }
View Full Code Here

TOP

Related Classes of org.wso2.carbon.governance.api.services.dataobjects.Service

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.