Package org.wso2.carbon.dashboard.mgt.gadgetrepo.ui

Examples of org.wso2.carbon.dashboard.mgt.gadgetrepo.ui.GadgetRepoServiceClient


* TODO: class description
*/
public final class Util {

    public static void checkAccess(String ownerTenantDomain, int ownerTenantId) {
        CarbonContext carbonContext = getCarbonContext();
        String callerTenantDomain = carbonContext.getTenantDomain();
        if (callerTenantDomain == null) {
            throw new IllegalStateException("Caller tenant domain cannot be null");
        }
        int callerTenantId = carbonContext.getTenantId();
        if (callerTenantId == MultitenantConstants.INVALID_TENANT_ID) {
            throw new IllegalStateException("Caller Tenant ID cannot be " + MultitenantConstants.INVALID_TENANT_ID);
        }

        if (callerTenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME) &&
View Full Code Here


                                        "],[" + callerTenantId + "]}");
        }
    }

    private static CarbonContext getCarbonContext() {
        CarbonContext carbonContext = CarbonContext.getThreadLocalCarbonContext();
        if (carbonContext == null) {
            throw new IllegalStateException("CarbonContext cannot be null");
        }
        return carbonContext;
    }
View Full Code Here

            PrivilegedCarbonContext.endTenantFlow();
        }
    }

    private void setTenantCredentialsInCarbonContext() {
        PrivilegedCarbonContext cc = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        cc.setTenantId(ownerTenantId);
        cc.setTenantDomain(ownerTenantDomain);
    }
View Full Code Here

        System.setProperty("carbon.home", new File(".").getAbsolutePath());

        String cacheName = "sampleCache";
        // CacheManager cacheManager = Caching.getCacheManager(); // same as Caching.getCacheManagerFactory().getCacheManager("__default__");

        PrivilegedCarbonContext cc = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        cc.setTenantDomain("foo.com");
        cc.setTenantId(1);

        CacheManager cacheManager = Caching.getCacheManagerFactory().getCacheManager("test");
        cache = cacheManager.getCache(cacheName);
    }
View Full Code Here

        String cookie = (String) request.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
        HttpSession session = request.getSession();

        String errorRedirect = null;
        try {
            GadgetRepoServiceClient client =
                    new GadgetRepoServiceClient(cookie, serverURL, configurationContext, request.getLocale());

            String gName = null;
            if (formFieldsMap.get("gadgetName") != null)
                gName = formFieldsMap.get("gadgetName").get(0);

            String gUrl = null;
            if (formFieldsMap.get("gadgetUrl") != null)
                gUrl = formFieldsMap.get("gadgetUrl").get(0);

            String gDesc = null;
            if (formFieldsMap.get("gadgetDesc") != null)
                gDesc = formFieldsMap.get("gadgetDesc").get(0);

            String formMode = null;
            if (formFieldsMap.get("mode") != null) {
                formMode = formFieldsMap.get("mode").get(0);
            }

            String gadgetPath = null;
            if (formFieldsMap.get("gadgetPath") != null) {
                gadgetPath = formFieldsMap.get("gadgetPath").get(0);
            }

            String redirect = null;
            if (formFieldsMap.get("redirect") != null) {
                redirect = formFieldsMap.get("redirect").get(0);
            }

            if (formFieldsMap.get("errorRedirect") != null) {
                errorRedirect = formFieldsMap.get("errorRedirect").get(0);
            }

            String symlinkLocation = null;
            if (formFieldsMap.get("symlinkLocation") != null) {
                symlinkLocation = formFieldsMap.get("symlinkLocation").get(0);
            }
            IServerAdmin adminClient =
                    (IServerAdmin) CarbonUIUtil.
                            getServerProxy(new ServerAdminClient(configurationContext,
                                    serverURL, cookie, session), IServerAdmin.class, session);
            ServerData data = adminClient.getServerData();
            String chroot = "";
            if (data.getRegistryType() != null && data.getRegistryType().equals("remote") &&
                    data.getRemoteRegistryChroot() != null &&
                    !data.getRemoteRegistryChroot().equals(RegistryConstants.PATH_SEPARATOR)) {
                chroot = data.getRemoteRegistryChroot();
                if (!chroot.startsWith(RegistryConstants.PATH_SEPARATOR)) {
                    chroot = RegistryConstants.PATH_SEPARATOR + chroot;
                }
                if (chroot.endsWith(RegistryConstants.PATH_SEPARATOR)) {
                    chroot = chroot.substring(0, chroot.length() - RegistryConstants.PATH_SEPARATOR.length());
                }
            }
            if (symlinkLocation != null) {
                symlinkLocation = chroot + symlinkLocation;
            }

            FileItemData gadgetScreenData = null;
            if (fileItemsMap.get("gadgetScreen") != null) {
                gadgetScreenData = fileItemsMap.get("gadgetScreen").get(0);
            }

            DataHandler gadgetThumb = null;
            if (gadgetScreenData != null) {
                gadgetThumb = gadgetScreenData.getDataHandler();
            }

            String cType = null;
            if (gadgetThumb != null) {
                cType = gadgetThumb.getContentType();
            }

            FileItemData gadgetArchive = null;
            if (fileItemsMap.get("gadget") != null) {
                gadgetArchive = fileItemsMap.get("gadget").get(0);
            } else if (gUrl == null || "".equals(gUrl)) {
                String msg = "Failed add resource. Gadget URL is empty";
                log.error(msg);

                if (errorRedirect == null) {
                    CarbonUIMessage.sendCarbonUIMessage(
                            msg, CarbonUIMessage.ERROR, request, response,
                            getContextRoot(request) + "/" +  webContext + "/admin/error.jsp");
                } else {
                    CarbonUIMessage.sendCarbonUIMessage(
                            msg, CarbonUIMessage.ERROR, request, response,
                            getContextRoot(request) + "/" + webContext + "/" + errorRedirect +
                            (errorRedirect.indexOf("?") == -1 ? "?" : "&") +
                            "msg=" + URLEncoder.encode(msg, "UTF-8"));
                }
                return false;

            }

            DataHandler gadgetFile = null;
            if (gadgetArchive != null) {
                gadgetFile = gadgetArchive.getDataHandler();
                if ("application/zip".equals(gadgetFile.getContentType())) {
                     /* This is a zip file. So upload gadget using zip file (Replaces new media type now). In this case
                     there is no gadget thumbnail. So use the cType var to store media type for gadget */
                    cType = DashboardConstants.GADGET_MEDIA_TYPE;
                }
            }

            if ("add".equals(formMode)) {
                Boolean created = client.addGadgetEntryToRepo(gName, gUrl, gDesc, gadgetThumb, cType, gadgetFile);
                if(!created){
                    String msg = "Can not add Gadget " + gName + ". Please refer error log for more details.";
                    log.info(msg);
                    CarbonUIMessage.sendCarbonUIMessage(
                            msg, CarbonUIMessage.ERROR, request, response,
                            getContextRoot(request) + "/" + webContext + "/admin/error.jsp");
                    return false;
                } else {
                    String msg = "Gadget " + gName + " added successfully.";
                    log.debug(msg);
                }
            } else if ("mod".equals(formMode)) {
                Boolean created = client.modifyGadgetEntry(gadgetPath, gName, gUrl, gDesc, gadgetThumb, cType, gadgetFile);
                if(!created){
                    String msg = "Can not modify Gadget" + gName + ". Please refer error log for more details.";
                    log.info(msg);
                    CarbonUIMessage.sendCarbonUIMessage(
                            msg, CarbonUIMessage.ERROR, request, response,
View Full Code Here

        }

        public void run() {
            try {
                MessageContext msgCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
                Event<MessageContext> event = new Event(msgCtx);
                subscriptions = subscriptionManager.getMatchingSubscriptions(event);
            } catch (EventException e) {
                handleException("Matching subscriptions fetching error", e);
            }
View Full Code Here

     * @throws EventException event
     */
    private void processGetStatusRequest(MessageContext mc,
                                         ResponseMessageBuilder messageBuilder)
            throws AxisFault, EventException {
        Subscription subscription =
                SubscriptionMessageBuilder.createGetStatusMessage(mc);
        if (log.isDebugEnabled()) {
            log.debug("GetStatus request recived for SynapseSubscription ID : " +
                    subscription.getId());
        }
        subscription = subscriptionManager.getSubscription(subscription.getId());
        if (subscription != null) {
            if (log.isDebugEnabled()) {
                log.debug("Sending GetStatus responce for SynapseSubscription ID : " +
                        subscription.getId());
            }
            //send the responce
            SOAPEnvelope soapEnvelope = messageBuilder.genGetStatusResponse(subscription);
            dispatchResponse(soapEnvelope, EventingConstants.WSE_GET_STATUS_RESPONSE,
                    mc, false);
View Full Code Here

            // Adding static subscriptions
            List<Subscription> staticSubscriptionList =
                    eventSource.getSubscriptionManager().getStaticSubscriptions();
            for (Iterator<Subscription> iterator = staticSubscriptionList.iterator();
                 iterator.hasNext();) {
                Subscription staticSubscription = iterator.next();
                OMElement staticSubElem =
                        fac.createOMElement("subscription", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
                staticSubElem.addAttribute(
                        fac.createOMAttribute("id", nullNS, staticSubscription.getId()));
                OMElement filterElem =
                        fac.createOMElement("filter", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
                filterElem.addAttribute(fac.createOMAttribute("source", nullNS,
                        (String) staticSubscription.getFilterValue()));
                filterElem.addAttribute(fac.createOMAttribute("dialect", nullNS,
                        (String) staticSubscription.getFilterDialect()));
                staticSubElem.addChild(filterElem);
                OMElement endpointElem =
                        fac.createOMElement("endpoint", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
                OMElement addressElem =
                        fac.createOMElement("address", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
                addressElem.addAttribute(
                        fac.createOMAttribute("uri", nullNS, staticSubscription.getEndpointUrl()));
                endpointElem.addChild(addressElem);
                staticSubElem.addChild(endpointElem);
                if (staticSubscription.getExpires() != null) {
                    OMElement expiresElem =
                            fac.createOMElement("expires", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
                    fac.createOMText(expiresElem,
                            ConverterUtil.convertToString(staticSubscription.getExpires()));
                    staticSubElem.addChild(expiresElem);
                }
                evenSourceElem.addChild(staticSubElem);
            }
View Full Code Here


    public SynapseSubscription() {
        this.setId(UIDGenerator.generateURNString());
        this.setDeliveryMode(EventingConstants.WSE_DEFAULT_DELIVERY_MODE);
        SubscriptionData subscriptionData = new SubscriptionData();
        subscriptionData.setProperty(SynapseEventingConstants.STATIC_ENTRY, "false");
        this.setSubscriptionData(subscriptionData);
    }
View Full Code Here

                    .getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "class"));
            if (clazz != null) {
                String className = clazz.getAttributeValue();
                try {
                    Class subscriptionManagerClass = Class.forName(className);
                    SubscriptionManager manager =
                            (SubscriptionManager) subscriptionManagerClass.newInstance();
                    Iterator itr = subscriptionManagerElem.getChildrenWithName(PROPERTIES_QNAME);
                    while (itr.hasNext()) {
                        OMElement propElem = (OMElement) itr.next();
                        String propName =
                                propElem.getAttribute(new QName("name")).getAttributeValue();
                        String propValue =
                                propElem.getAttribute(new QName("value")).getAttributeValue();
                        if (propName != null && !"".equals(propName.trim()) &&
                                propValue != null && !"".equals(propValue.trim())) {

                            propName = propName.trim();
                            propValue = propValue.trim();

                            PasswordManager passwordManager =
                                    PasswordManager.getInstance();
                            String key = eventSource.getName() + "." + propName;

                            if (passwordManager.isInitialized()
                                    && passwordManager.isTokenProtected(key)) {
                                eventSource.putConfigurationProperty(propName, propValue);
                                propValue = passwordManager.resolve(propValue);
                            }

                            manager.addProperty(propName, propValue);
                        }
                    }
                    eventSource.setSubscriptionManager(manager);
                    eventSource.getSubscriptionManager()
                            .init(); // Initialise before doing further processing, required for static subscriptions
View Full Code Here

TOP

Related Classes of org.wso2.carbon.dashboard.mgt.gadgetrepo.ui.GadgetRepoServiceClient

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.