Package org.apache.ace.client.repository.object

Examples of org.apache.ace.client.repository.object.ArtifactObject


    }

    @Test( groups = { TestUtils.UNIT } )
    public void testGetAssociationsWith() {
        initializeRepositoryAdmin();
        ArtifactObject b1 = createBasicBundleObject("bundle1");
        GroupObject g1 = createBasicGroupObject("group1");
        Artifact2GroupAssociation b2g1 = m_artifact2groupRepository.create(b1, g1);

        List<Artifact2GroupAssociation> b1Associations = b1.getAssociationsWith(g1);
        List<Artifact2GroupAssociation> g1Associations = g1.getAssociationsWith(b1);

        assert b1Associations.size() == 1 : "The bundle has exactly one association to the group, but it shows " + b1Associations.size() + ".";
        assert b1Associations.get(0) == b2g1 : "The bundle's association should be the one we created.";
View Full Code Here


        assert for1.get(0) == version1 : "The only version for" + gwId +  "should be version1";
    }

    @Test( groups = { TestUtils.UNIT } )
    public void testAssociationsWithLists() {
        ArtifactObject b1 = createBasicBundleObject("b1");
        ArtifactObject b2 = createBasicBundleObject("b2");
        ArtifactObject b3 = createBasicBundleObject("b3");
        GroupObject g1 = createBasicGroupObject("g1");
        GroupObject g2 = createBasicGroupObject("g2");
        GroupObject g3 = createBasicGroupObject("g3");

        List<ArtifactObject> bundles = new ArrayList<ArtifactObject>();
        bundles.add(b1);
        bundles.add(b2);
        List<GroupObject> groups = new ArrayList<GroupObject>();
        groups.add(g1);
        groups.add(g3);

        Artifact2GroupAssociation bg = m_artifact2groupRepository.create(bundles, groups);

        assert bg.getLeft().size() == 2 : "We expect two bundles on the left side of the association.";
        assert bg.getRight().size() == 2 : "We expect two groups on the right side of the association.";

        assert bg.getLeft().contains(b1) : "b1 should be on the left side of the association.";
        assert bg.getLeft().contains(b2) : "b2 should be on the left side of the association.";
        assert !bg.getLeft().contains(b3) : "b3 should not be on the left side of the association.";
        assert bg.getRight().contains(g1) : "g1 should be on the right side of the association.";
        assert !bg.getRight().contains(g2) : "g2 should not be on the right side of the association.";
        assert bg.getRight().contains(g3) : "g3 should be on the right side of the association.";

        List<GroupObject> foundGroups = b1.getGroups();
        assert foundGroups.size() == 2 : "b1 should be associated with two groups.";
        assert foundGroups.contains(g1) : "b1 should be associated with g1";
        assert !foundGroups.contains(g2) : "b1 not should be associated with g2";
        assert foundGroups.contains(g3) : "b1 should be associated with g3";

        foundGroups = b3.getGroups();
        assert foundGroups.size() == 0 : "b3 should not be associated with any groups.";

        List<ArtifactObject> foundBundles = g3.getArtifacts();
        assert foundBundles.size() == 2 : "g1 should be associated with two groups.";
        assert foundBundles.contains(b1) : "g1 should be associated with b1";
View Full Code Here

        assert !foundBundles.contains(b3) : "g1 should not be associated with b3";
    }

    @Test( groups = { TestUtils.UNIT } )
    public void testAssociationsWithCardinality() {
        ArtifactObject b1 = createBasicBundleObject("b1");
        GroupObject g1 = createBasicGroupObject("g1");
        GroupObject g2 = createBasicGroupObject("g2");
        GroupObject g3 = createBasicGroupObject("g3");

        Map<String, String> props = new HashMap<String, String>();
        props.put(Association.LEFT_ENDPOINT, "(" + BundleHelper.KEY_SYMBOLICNAME + "=b1)");
        props.put(Association.LEFT_CARDINALITY, "1");
        props.put(Association.RIGHT_ENDPOINT, "(" + GroupObject.KEY_NAME + "=g*)");
        props.put(Association.RIGHT_CARDINALITY, "2");
        Map<String, String> tags = new HashMap<String, String>();

        try {
            m_artifact2groupRepository.create(props, tags);
            assert false : "There are three matches for the group, but we have a cardinality of 2; we should expect a NPE because no comparator is provided.";
        }
        catch (NullPointerException npe) {
            //expected
        }

        props.put(Association.RIGHT_CARDINALITY, "3");

        Artifact2GroupAssociation bg = m_artifact2groupRepository.create(props, tags);
        assert b1.getGroups().size() == 3 : "The bundle should be associated to three groups.";
        assert (g1.getArtifacts().size() == 1) && g1.getArtifacts().contains(b1) : "g1 should be associated to only b1.";
        assert (g2.getArtifacts().size() == 1) && g2.getArtifacts().contains(b1) : "g1 should be associated to only b1.";
        assert (g3.getArtifacts().size() == 1) && g3.getArtifacts().contains(b1) : "g1 should be associated to only b1.";
    }
View Full Code Here

        }

        // Determine all resource processors we need
        for (String processor : artifacts.values()) {
            if (!bundles.containsValue(processor)) {
                ArtifactObject bundle = allProcessors.get(processor);
                if (bundle == null) {
                    m_log.log(LogService.LOG_ERROR, "Unable to create deployment version: there is no resource processing bundle available that publishes " + processor);
                    throw new IllegalStateException("Unable to create deployment version: there is no resource processing bundle available that publishes " + processor);
                }
                bundles.put(bundle, processor);
            }
        }

        List<DeploymentArtifact> result = new ArrayList<DeploymentArtifact>();

        for (ArtifactObject bundle : bundles.keySet()) {
            Map<String, String> directives = new HashMap<String, String>();
            if (m_bundleHelper.isResourceProcessor(bundle)) {
                // it's a resource processor, mark it as such.
                directives.put(DeploymentArtifact.DIRECTIVE_ISCUSTOMIZER, "true");
            }
            directives.put(BundleHelper.KEY_SYMBOLICNAME, m_bundleHelper.getSymbolicName(bundle));
            String bundleVersion = m_bundleHelper.getVersion(bundle);
            if (bundleVersion != null) {
                directives.put(BundleHelper.KEY_VERSION, bundleVersion);
            }
            directives.put(DeploymentArtifact.DIRECTIVE_KEY_BASEURL, bundle.getURL());
            result.add(m_deploymentRepository.createDeploymentArtifact(bundle.getURL(), directives));
        }

        for (ArtifactObject artifact : artifacts.keySet()) {
            Map<String, String> directives = new HashMap<String, String>();
            directives.put(DeploymentArtifact.DIRECTIVE_KEY_PROCESSORID, artifact.getProcessorPID());
View Full Code Here

            for (LicenseObject license : go.getLicenses()) {
                for (GroupObject group : license.getGroups()) {
                    for (ArtifactObject artifact : group.getArtifacts()) {
                        result.add(artifact);
                        if (!m_bundleHelper.canUse(artifact)) {
                            ArtifactObject processor = allProcessors.get(artifact.getProcessorPID());
                            if (processor == null) {
                                // this means we cannot create a useful version; return null.
                                return null;
                            }
                            result.add(processor);
View Full Code Here

                    for (Object id : artifacts.getItemIds()) {
                        if (artifacts.isSelected(id)) {
                            for (OBREntry e : m_obrList) {
                                if (e.getUri().equals(id)) {
                                    try {
                                        ArtifactObject ao = importBundle(e);
                                        added.add(ao);
                                    }
                                    catch (Exception e1) {
                                        getMainWindow().showNotification(
                                            "Import artifact failed",
                                            "Artifact " + e.getSymbolicName() + " " + e.getVersion() + "<br />could not be imported into the repository.<br />" +
                                            "Reason: " + e1.getMessage(),
                                            Notification.TYPE_ERROR_MESSAGE);
                                        m_log.log(LogService.LOG_ERROR, "Import of " + e.getSymbolicName() + " " + e.getVersion() + " failed.", e1);
                                    }
                                }
                            }
                        }
                    }
                    for (File artifact : m_uploadedArtifacts) {
                      try {
                        ArtifactObject ao = importBundle(artifact.toURI().toURL());
                            added.add(ao);
            }
                      catch (Exception e) {
                            getMainWindow().showNotification(
                                "Import artifact failed",
View Full Code Here

            // expected
        }

        m_artifactRepository.addHelper("myMime", helper);

        ArtifactObject obj = createArtifact("myMime", "myUrl", null, null);

        assert obj.getURL().equals("yourURL");

        try {
            m_artifactRepository.getHelper("yourMime");
            assert false : "We have not registered this helper.";
        }
View Full Code Here

    @Test( groups = { TestUtils.UNIT } )
    public void testResourceProcessorFiltering() throws InvalidSyntaxException {
        m_artifactRepository.addHelper("myMime", new MockHelper());
        m_artifactRepository.addHelper(BundleHelper.MIMETYPE, new BundleHelperImpl());

        ArtifactObject normalBundle = createArtifact(BundleHelper.MIMETYPE, "normalBundle", "normalBundle", null);

        ArtifactObject resourceProcessor1 = createArtifact(BundleHelper.MIMETYPE, "resourceProcessor1", "resourceProcessor1", "somePID");
        ArtifactObject resourceProcessor2 = createArtifact(BundleHelper.MIMETYPE, "resourceProcessor2", "resourceProcessor2", "someOtherPID");

        ArtifactObject myArtifact = createArtifact("myMime", "myArtifact", null, null);

        assert m_artifactRepository.get().size() == 2 : "We expect to find two artifacts, but we find " + m_artifactRepository.get().size();

        List<ArtifactObject> list = m_artifactRepository.get(m_artifactRepository.createFilter("(!(" + BundleHelper.KEY_SYMBOLICNAME + "=normalBundle))"));
        assert (list.size() == 1) && list.contains(myArtifact) : "We expect to find one artifact when filtering, but we find " + list.size();
View Full Code Here

            protected void associateFromLeft(String left, String right) {
            }

            @Override
            protected void associateFromRight(String left, String right) {
                ArtifactObject artifact = getArtifact(left);
                // if you drop on a resource processor, and try to get it, you will get null
                // because you cannot associate anything with a resource processor so we check
                // for null here
                if (artifact != null) {
                    if (m_dynamicRelations) {
                        Map<String, String> properties = new HashMap<String, String>();
                        properties.put(BundleHelper.KEY_ASSOCIATION_VERSIONSTATEMENT, "0.0.0");
                        m_artifact2GroupAssociationRepository.create(artifact, properties, getFeature(right), null);
                    }
                    else {
                        m_artifact2GroupAssociationRepository.create(artifact, getFeature(right));
                    }
                }
            }
        });
        m_featuresPanel.setDropHandler(new AssociationDropHandler(m_artifactsPanel, m_distributionsPanel) {
            @Override
            protected void associateFromLeft(String left, String right) {
                ArtifactObject artifact = getArtifact(left);
                // if you drop on a resource processor, and try to get it, you will get null
                // because you cannot associate anything with a resource processor so we check
                // for null here
                if (artifact != null) {
                    if (m_dynamicRelations) {
View Full Code Here

                    add(artifact);
                }
            }

            public void handleEvent(org.osgi.service.event.Event event) {
                ArtifactObject artifact = (ArtifactObject) event.getProperty(ArtifactObject.EVENT_ENTITY);
                String topic = (String) event.getProperty(EventConstants.EVENT_TOPIC);
                if (ArtifactObject.TOPIC_ADDED.equals(topic)) {
                    add(artifact);
                }
                if (ArtifactObject.TOPIC_REMOVED.equals(topic)) {
                    remove(artifact);
                }
                if (ArtifactObject.TOPIC_CHANGED.equals(topic)) {
                    change(artifact);
                }
            }

            private void add(ArtifactObject artifact) {
                String resourceProcessorPID = artifact.getAttribute(BundleHelper.KEY_RESOURCE_PROCESSOR_PID);
                if (resourceProcessorPID != null) {
                  // if it's a resource processor we don't add it to our list, as resource processors don't
                  // show up there (you can query for them separately)

                  return;
                }
                Item item = addItem(artifact.getName());
                item.getItemProperty(OBJECT_NAME).setValue(artifact.getName());
                item.getItemProperty(OBJECT_DESCRIPTION).setValue(artifact.getDescription());
                HorizontalLayout buttons = new HorizontalLayout();
                Button removeLinkButton = new RemoveLinkButton<ArtifactObject>(artifact, null, m_featuresPanel) {
                    @Override
                    protected void removeLinkFromLeft(ArtifactObject object, RepositoryObject other) {}
                   
                    @Override
                    protected void removeLinkFromRight(ArtifactObject object, RepositoryObject other) {
                        List<Artifact2GroupAssociation> associations = object.getAssociationsWith((GroupObject) other);
                        for (Artifact2GroupAssociation association : associations) {
                            m_artifact2GroupAssociationRepository.remove(association);
                        }
                        m_associations.removeAssociatedItem(object);
                        m_table.requestRepaint();
                    }
                };
                buttons.addComponent(removeLinkButton);
                buttons.addComponent(new RemoveItemButton<ArtifactObject, ArtifactRepository>(artifact, m_artifactRepository));
                item.getItemProperty(ACTIONS).setValue(buttons);

            }
            private void change(ArtifactObject artifact) {
                Item item = getItem(artifact.getName());
                item.getItemProperty(OBJECT_DESCRIPTION).setValue(artifact.getDescription());
            }
            private void remove(ArtifactObject artifact) {
                removeItem(artifact.getName());
            }
        };
    }
View Full Code Here

TOP

Related Classes of org.apache.ace.client.repository.object.ArtifactObject

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.