Examples of GadgetRepoServiceClient


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

        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
TOP
Copyright © 2018 www.massapi.com. 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.