Search in sources :

Example 1 with XmlDeploymentPackage

use of org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage in project kura by eclipse.

the class CloudDeploymentHandlerV2 method doGetPackages.

private void doGetPackages(KuraResponsePayload response) {
    DeploymentPackage[] dps = this.m_deploymentAdmin.listDeploymentPackages();
    XmlDeploymentPackages xdps = new XmlDeploymentPackages();
    XmlDeploymentPackage[] axdp = new XmlDeploymentPackage[dps.length];
    for (int i = 0; i < dps.length; i++) {
        DeploymentPackage dp = dps[i];
        XmlDeploymentPackage xdp = new XmlDeploymentPackage();
        xdp.setName(dp.getName());
        xdp.setVersion(dp.getVersion().toString());
        BundleInfo[] bis = dp.getBundleInfos();
        XmlBundleInfo[] axbi = new XmlBundleInfo[bis.length];
        for (int j = 0; j < bis.length; j++) {
            BundleInfo bi = bis[j];
            XmlBundleInfo xbi = new XmlBundleInfo();
            xbi.setName(bi.getSymbolicName());
            xbi.setVersion(bi.getVersion().toString());
            axbi[j] = xbi;
        }
        xdp.setBundleInfos(axbi);
        axdp[i] = xdp;
    }
    xdps.setDeploymentPackages(axdp);
    try {
        String s = XmlUtil.marshal(xdps);
        response.setTimestamp(new Date());
        response.setBody(s.getBytes("UTF-8"));
    } catch (Exception e) {
        s_logger.error("Error getting resource {}: {}", RESOURCE_PACKAGES, e);
    }
}
Also used : DeploymentPackage(org.osgi.service.deploymentadmin.DeploymentPackage) XmlDeploymentPackage(org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage) XmlDeploymentPackage(org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage) XmlBundleInfo(org.eclipse.kura.core.deployment.xml.XmlBundleInfo) XmlDeploymentPackages(org.eclipse.kura.core.deployment.xml.XmlDeploymentPackages) Date(java.util.Date) ComponentException(org.osgi.service.component.ComponentException) KuraException(org.eclipse.kura.KuraException) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BundleInfo(org.osgi.service.deploymentadmin.BundleInfo) XmlBundleInfo(org.eclipse.kura.core.deployment.xml.XmlBundleInfo)

Example 2 with XmlDeploymentPackage

use of org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage in project kura by eclipse.

the class XmlUtilTest method getSampleXmlDeploymentPackagesObject.

private static XmlDeploymentPackages getSampleXmlDeploymentPackagesObject() {
    XmlDeploymentPackages xmlDeploymentPackages = new XmlDeploymentPackages();
    XmlBundleInfo inputXmlBundleInfo = new XmlBundleInfo();
    inputXmlBundleInfo.setName("XmlBundleInfo");
    inputXmlBundleInfo.setVersion("3.0.1.201");
    XmlDeploymentPackage inputXmlDeploymentPackage = new XmlDeploymentPackage();
    inputXmlDeploymentPackage.setName("raspberry");
    inputXmlDeploymentPackage.setVersion("3.0.1");
    inputXmlDeploymentPackage.setBundleInfos(new XmlBundleInfo[] { inputXmlBundleInfo });
    xmlDeploymentPackages.setDeploymentPackages(new XmlDeploymentPackage[] { inputXmlDeploymentPackage });
    return xmlDeploymentPackages;
}
Also used : XmlDeploymentPackage(org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage) XmlBundleInfo(org.eclipse.kura.core.deployment.xml.XmlBundleInfo) XmlDeploymentPackages(org.eclipse.kura.core.deployment.xml.XmlDeploymentPackages)

Example 3 with XmlDeploymentPackage

use of org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage in project kura by eclipse.

the class CloudDeploymentHandlerTest method testGetPackages.

@TestTarget(targetPlatforms = { TestTarget.PLATFORM_ALL })
@Test
@Ignore
public void testGetPackages() throws Exception {
    assertTrue(s_cloudCallService.isConnected());
    DeploymentPackage dp = s_deploymentAdmin.getDeploymentPackage(LOCAL_DP_NAME);
    if (dp == null) {
        s_logger.warn("Getting dp");
        InputStream is = getTestDpUrl().openStream();
        dp = s_deploymentAdmin.installDeploymentPackage(is);
    }
    StringBuilder sb = new StringBuilder(CloudletTopic.Method.GET.toString()).append("/").append(CloudDeploymentHandlerV2.RESOURCE_PACKAGES);
    KuraResponsePayload resp = s_cloudCallService.call(CloudDeploymentHandlerV2.APP_ID, sb.toString(), null, 5000);
    assertEquals(KuraResponsePayload.RESPONSE_CODE_OK, resp.getResponseCode());
    String s = new String(resp.getBody());
    // XmlDeploymentPackages xmlPackages = XmlUtil.unmarshal(s, XmlDeploymentPackages.class);
    XmlDeploymentPackages xmlPackages = CoreTestXmlUtil.unmarshal(s, XmlDeploymentPackages.class);
    XmlDeploymentPackage[] packages = xmlPackages.getDeploymentPackages();
    XmlDeploymentPackage xmlDp = null;
    if (packages != null) {
        for (int i = 0; i < packages.length; i++) {
            if (packages[i].getName().equals(LOCAL_DP_NAME)) {
                xmlDp = packages[i];
                break;
            }
        }
    }
    assertNotNull(xmlDp);
    assertEquals(LOCAL_DP_VERSION, xmlDp.getVersion());
    XmlBundleInfo[] bundleInfos = xmlDp.getBundleInfos();
    assertEquals(1, bundleInfos.length);
    assertEquals(LOCAL_BUNDLE_NAME, bundleInfos[0].getName());
    assertEquals(LOCAL_BUNDLE_VERSION, bundleInfos[0].getVersion());
}
Also used : InputStream(java.io.InputStream) DeploymentPackage(org.osgi.service.deploymentadmin.DeploymentPackage) XmlDeploymentPackage(org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage) XmlDeploymentPackage(org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage) KuraResponsePayload(org.eclipse.kura.message.KuraResponsePayload) XmlBundleInfo(org.eclipse.kura.core.deployment.xml.XmlBundleInfo) XmlDeploymentPackages(org.eclipse.kura.core.deployment.xml.XmlDeploymentPackages) Ignore(org.junit.Ignore) TestTarget(org.eclipse.kura.test.annotation.TestTarget) Test(org.junit.Test)

Example 4 with XmlDeploymentPackage

use of org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage in project kura by eclipse.

the class CoreTestXmlUtil method unmarshalXmlDeploymentPackages.

// unmarshal XmlDeploymentPackages
@SuppressWarnings("unchecked")
public static <T> T unmarshalXmlDeploymentPackages(Document doc) throws Exception {
    // Java objects for unmarshal
    XmlDeploymentPackages xmlDeploymentPackages = new XmlDeploymentPackages();
    List<XmlDeploymentPackage> xmlDeploymentPackageList = new ArrayList<XmlDeploymentPackage>();
    // XML elements
    Element packages = doc.getDocumentElement();
    NodeList packagesChildren = packages.getChildNodes();
    // Collect all packages
    for (int propIndex = 0; propIndex < packagesChildren.getLength(); propIndex++) {
        Node currentNode = packagesChildren.item(propIndex);
        if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
            Element el = (Element) currentNode;
            if (el.getNodeName().equals("package")) {
                XmlDeploymentPackage xdp = new XmlDeploymentPackage();
                NodeList nodeList = el.getChildNodes();
                for (int i = 0; i < nodeList.getLength(); i++) {
                    Node tmpNode = nodeList.item(i);
                    // Set package name
                    if (tmpNode.getNodeName().equals("name"))
                        xdp.setName(tmpNode.getTextContent());
                    else // Set package version
                    if (tmpNode.getNodeName().equals("version"))
                        xdp.setVersion(tmpNode.getTextContent());
                    else // Set bundle info
                    if (tmpNode.getNodeName().equals("bundles"))
                        xdp.setBundleInfos(parseBundles(tmpNode));
                }
                xmlDeploymentPackageList.add(xdp);
            }
        }
    }
    // Add packages
    xmlDeploymentPackages.setDeploymentPackages(xmlDeploymentPackageList.toArray(new XmlDeploymentPackage[xmlDeploymentPackageList.size()]));
    return (T) xmlDeploymentPackages;
}
Also used : Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) XmlDeploymentPackage(org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage) ArrayList(java.util.ArrayList) XmlDeploymentPackages(org.eclipse.kura.core.deployment.xml.XmlDeploymentPackages)

Example 5 with XmlDeploymentPackage

use of org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage in project kura by eclipse.

the class XmlJavaPackagesMapper method marshal.

@Override
public Element marshal(Document doc, Object object) throws Exception {
    Element packages = doc.createElement(PACKAGES);
    doc.appendChild(packages);
    XmlDeploymentPackages xdps = (XmlDeploymentPackages) object;
    XmlDeploymentPackage[] xdpArray = xdps.getDeploymentPackages();
    for (XmlDeploymentPackage xdp : xdpArray) {
        Element packageInstalled = doc.createElement(PACKAGES_PACKAGE);
        marshalDeploymentPackage(doc, xdp, packageInstalled);
        packages.appendChild(packageInstalled);
    }
    return packages;
}
Also used : Element(org.w3c.dom.Element) XmlDeploymentPackage(org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage) XmlDeploymentPackages(org.eclipse.kura.core.deployment.xml.XmlDeploymentPackages)

Aggregations

XmlDeploymentPackage (org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage)5 XmlDeploymentPackages (org.eclipse.kura.core.deployment.xml.XmlDeploymentPackages)5 XmlBundleInfo (org.eclipse.kura.core.deployment.xml.XmlBundleInfo)3 DeploymentPackage (org.osgi.service.deploymentadmin.DeploymentPackage)2 Element (org.w3c.dom.Element)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 KuraException (org.eclipse.kura.KuraException)1 KuraResponsePayload (org.eclipse.kura.message.KuraResponsePayload)1 TestTarget (org.eclipse.kura.test.annotation.TestTarget)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 BundleException (org.osgi.framework.BundleException)1 ComponentException (org.osgi.service.component.ComponentException)1 BundleInfo (org.osgi.service.deploymentadmin.BundleInfo)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1