Package org.wso2.carbon.registry.core

Examples of org.wso2.carbon.registry.core.Resource


    public void loadSchemaDetails() throws GovernanceException {
        checkRegistryResourceAssociation();
        Registry registry = getAssociatedRegistry();
        String path = getPath();
        String id = getId();
        Resource resource;
        try {
            resource = registry.get(path);
            byte[] content = (byte[]) resource.getContent();
            schemaElement = GovernanceUtils.buildOMElement(content);

        } catch (RegistryException e) {
            String msg =
                    "Error in getting the content for the artifact. artifact id: " + id + ", " +
                            "path: " + path + ".";
            log.error(msg);
            throw new GovernanceException(msg, e);
        }
        // get the target namespace.
        String fileName = RegistryUtils.getResourceName(path);
        String namespaceURI =
                schemaElement.getAttributeValue(new QName(SCHEMA_TARGET_NAMESPACE_ATTRIBUTE));
        qname = new QName(namespaceURI, fileName);

        // and then iterate all the properties and add.
        Properties properties = resource.getProperties();
        if (properties != null) {
            Set keySet = properties.keySet();
            if (keySet != null) {
                for (Object keyObj : keySet) {
                    String key = (String) keyObj;
View Full Code Here


                        + DashboardConstants.TAB_PATH
                        + tabId
                        + DashboardConstants.CURRENT_GADGET_LAYOUT_PATH;
            }

            Resource gadgetLayout;
            if (registry.resourceExists(gadgetLayoutPath)) {
                gadgetLayout = registry.get(gadgetLayoutPath);
            } else {
                gadgetLayout = registry.newCollection();
            }

            //get the column which the new gadget should be added to have a equal distribution <column, numberOfGadgets>
            HashMap<Integer, Integer> gadgets = new HashMap<Integer, Integer>();
            String layout = getGadgetLayout(userId, tabId, dashboardName);
            if (layout.equals("NA")) {
                layout = "{layout:[]}";
            }
            // to hold the sorted result
            HashMap<Integer, Integer> map = new LinkedHashMap<Integer, Integer>();
            JSONObject json = null;
            try {
                json = new JSONObject(layout);


            } catch (Exception e) {
                log.error("JSONParser unsuccessful : ", e);
            }

            for (int i = 0; i < json.getJSONArray("layout").length(); i++) {
                JSONArray numberOfGadgetsInColumn = json.getJSONArray("layout").getJSONObject(i).getJSONArray("layout");
                gadgets.put(i, numberOfGadgetsInColumn.length());
            }

            List<Integer> mapKeys = new ArrayList<Integer>(gadgets.keySet());
            List<Integer> mapValues = new ArrayList<Integer>(gadgets.values());
            TreeSet<Integer> sortedSet = new TreeSet<Integer>(mapValues);
            Object[] sortedArray = sortedSet.toArray();
            int size = sortedArray.length;

            for (int i = 0; i < size; i++) {
                map.put
                        (mapKeys.get(mapValues.indexOf(sortedArray[i])),
                                Integer.parseInt(sortedArray[i].toString()));
            }

            List<Integer> ref = new ArrayList<Integer>(map.keySet());

            // Retrieving the gadget layout
            String currentLayout = gadgetLayout
                    .getProperty(DashboardConstants.CURRENT_GADGET_LAYOUT);

            int colNum = 0;
            if (ref.size() != 0) {
                colNum = ref.get(0);
            }

            gadgetLayout.setProperty(DashboardConstants.CURRENT_GADGET_LAYOUT,
                    insertGadgetToJsonLayout(currentLayout, gadgetId, colNum).toString());

            registry.put(gadgetLayoutPath, gadgetLayout);

            // Done
View Full Code Here

            registry.beginTransaction();

            if (registry.resourceExists(resourcePath)) {
                registry.delete(resourcePath);
            }
            Resource resource = registry.newResource();
            resource.setContent(element.toString());
            if (fileName != null) {
                resource.setProperty(ServiceBusConstants.DEFINITION_FILE_NAME, fileName);
            }
            resource.setMediaType("text/xml");
            registry.put(resourcePath, resource);
            registry.commitTransaction();

        } catch (Exception e) {
            registry.rollbackTransaction();
View Full Code Here

            nextGadgetIdPath = DashboardConstants.SYSTEM_DASHBOARDS_REGISTRY_ROOT
                    + dashboardName
                    + DashboardConstants.NEXT_GADGET_ID_PATH;
        }

        Resource nextGadgetIdResource;
        if (registry.resourceExists(nextGadgetIdPath)) {
            nextGadgetIdResource = registry.get(nextGadgetIdPath);
        } else {
            nextGadgetIdResource = registry.newCollection();
        }


        // Generating a unique ID for this gadget
        int nextGadgetId;
        String gadgetId = "0";
        if (nextGadgetIdResource
                .getProperty(DashboardConstants.NEXT_GADGET_ID) != null) {
            // We need to use that
            gadgetId = nextGadgetIdResource
                    .getProperty(DashboardConstants.NEXT_GADGET_ID);
        }
        // Increment and update counter
        nextGadgetId = Integer.parseInt(gadgetId) + 1;
        nextGadgetIdResource.setProperty(DashboardConstants.NEXT_GADGET_ID,
                String.valueOf(nextGadgetId));
        registry.put(nextGadgetIdPath, nextGadgetIdResource);

        // Adding the new gadget to registry
        String newGadgetPath;
        if ((dashboardName == null) || ("null".equals(dashboardName))) {
            newGadgetPath = DashboardConstants.USER_DASHBOARD_REGISTRY_ROOT
                    + userId + DashboardConstants.REGISTRY_PRODUCT_ID_PATH
                    + DashboardConstants.GADGET_PATH + gadgetId;
        } else {
            newGadgetPath = DashboardConstants.SYSTEM_DASHBOARDS_REGISTRY_ROOT
                    + dashboardName
                    + DashboardConstants.GADGET_PATH
                    + gadgetId;
        }

        Resource newGadgetResource;
        if (registry.resourceExists(newGadgetPath)) {
            newGadgetResource = registry.get(newGadgetPath);
        } else {
            newGadgetResource = registry.newCollection();
        }
        // Storing the gadget url as a property and adding the new gadget
        newGadgetResource.setProperty(DashboardConstants.GADGET_URL, url);
        registry.put(newGadgetPath, newGadgetResource);
        return gadgetId;
    }
View Full Code Here

    }

    protected Collection<OMElement> getChildElementsInPath(String path) throws RegistryException {
        Collection<OMElement> childElements = new ArrayList<OMElement>();
        if (registry.resourceExists(path)) {
            Resource resource = registry.get(path);
            if (resource instanceof org.wso2.carbon.registry.core.Collection) {
                org.wso2.carbon.registry.core.Collection collection
                        = (org.wso2.carbon.registry.core.Collection) resource;
                String[] children = collection.getChildren();
                for (String resourcePath : children) {
View Full Code Here

        return childElements;
    }

    protected OMElement getResourceAsElement(String resourcePath) throws RegistryException {
        OMElement resourceElem = null;
        Resource childResource = registry.get(resourcePath);
        try {
            resourceElem = new StAXOMBuilder(
                    childResource.getContentStream()).getDocumentElement();
            resourceElem.build();
            String fileNameProperty
                    = childResource.getProperty(ServiceBusConstants.DEFINITION_FILE_NAME);
            if (fileNameProperty != null) {
                resourceElem.addAttribute(ServiceBusConstants.DEFINITION_FILE_NAME,
                        fileNameProperty, resourceElem.getOMFactory().createOMNamespace("", ""));
            }
        } catch (XMLStreamException e) {
View Full Code Here

            gadgetPath = DashboardConstants.SYSTEM_DASHBOARDS_REGISTRY_ROOT
                    + dashboardName + DashboardConstants.GADGET_PATH + gadgetId;
        }
        try {
            Registry registry = getConfigSystemRegistry();
            Resource gadgetRes = registry.get(gadgetPath);
            gadgetUrl = gadgetRes.getProperty(DashboardConstants.GADGET_URL);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return gadgetUrl;
    }
View Full Code Here

        try {
            registry = getConfigSystemRegistry();
            // Need not do any null checks for registry, as if so, we'll never
            // get here.
            registry.beginTransaction();
            Resource userTabResource = registry.get(dashboardTabPath);

            // First generate the new Id
            String nextTabId = userTabResource
                    .getProperty(DashboardConstants.NEXT_TAB_ID);
            if (nextTabId == null) {
                // This is the first tab after home [0]
                nextTabId = "1";
            }
            // Persisting the updated counter
            userTabResource.setProperty(DashboardConstants.NEXT_TAB_ID, String
                    .valueOf(Integer.parseInt(nextTabId) + 1));
            registry.put(dashboardTabPath, userTabResource);

            // Creating a new tab resource
            Resource newTab = registry.newCollection();

            // Storing the name of the tab
            if ("".equals(tabTitle)) {
                tabTitle = "Tab " + nextTabId;
            }
            newTab.setProperty(DashboardConstants.TAB_TITLE, tabTitle);

            String newTabPath = dashboardTabPath + nextTabId;
            registry.put(newTabPath, newTab);

            // Retrieving the current tab layout
View Full Code Here

                    + dashboardName + DashboardConstants.TAB_PATH + tabId;
        }

        try {
            Registry registry = getConfigSystemRegistry();
            Resource tabResource = registry.get(tabPath);
            if (tabResource.getProperty(DashboardConstants.TAB_TITLE) != null) {
                return tabResource.getProperty(DashboardConstants.TAB_TITLE);
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
View Full Code Here

            if (!Transaction.isStarted()) {
                registry.beginTransaction();
                transactionStarted = true;
            }
            Resource userTabResource = registry.get(dashboardTabPath);

            // First remove this tab from the tab layout
            String currentTabLayout = userTabResource
                    .getProperty(DashboardConstants.CURRENT_TAB_LAYOUT);
            String[] tabIds = currentTabLayout.split(",");
            String newTabLayout = "";
            for (String tabId1 : tabIds) {
                if (!tabId1.equals(tabId)) {
                    if (newTabLayout.equals("")) {
                        newTabLayout = tabId1;
                    } else {
                        newTabLayout = newTabLayout + "," + tabId1;
                    }
                }
            }
            userTabResource.setProperty(DashboardConstants.CURRENT_TAB_LAYOUT,
                    newTabLayout);
            registry.put(dashboardTabPath, userTabResource);

            // Then remove all the Gadgets belonging to this tab
            JSONObject currentLayout = new JSONObject(getGadgetLayout(userId, tabId, dashboardName));
View Full Code Here

TOP

Related Classes of org.wso2.carbon.registry.core.Resource

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.