Search in sources :

Example 1 with Initialize

use of cz.metacentrum.perun.webgui.json.registrarManager.Initialize in project perun by CESNET.

the class ApplicationFormGui method loadVo.

/**
	 * Loads the VO by the parameter
	 */
public void loadVo(final JsonCallbackEvents events) {
    voName = Location.getParameter("vo");
    groupName = Location.getParameter("group");
    Initialize req = new Initialize(voName, groupName, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            JsArray<Attribute> list = JsonUtils.jsoAsArray(jso);
            // recreate VO and group
            vo = new JSONObject().getJavaScriptObject().cast();
            if (groupName != null && !groupName.isEmpty()) {
                group = new JSONObject().getJavaScriptObject().cast();
            }
            for (int i = 0; i < list.length(); i++) {
                Attribute a = list.get(i);
                if (a.getFriendlyName().equalsIgnoreCase("id")) {
                    if (a.getNamespace().equalsIgnoreCase("urn:perun:vo:attribute-def:core")) {
                        vo.setId(Integer.parseInt(a.getValue()));
                        if (group != null) {
                            group.setVoId(Integer.parseInt(a.getValue()));
                        }
                    } else if (a.getNamespace().equalsIgnoreCase("urn:perun:group:attribute-def:core")) {
                        group.setId(Integer.parseInt(a.getValue()));
                    }
                } else if (a.getFriendlyName().equalsIgnoreCase("name")) {
                    if (a.getNamespace().equalsIgnoreCase("urn:perun:vo:attribute-def:core")) {
                        vo.setName(a.getValue());
                    } else if (a.getNamespace().equalsIgnoreCase("urn:perun:group:attribute-def:core")) {
                        group.setName(a.getValue());
                    }
                } else if (a.getFriendlyName().equalsIgnoreCase("shortName")) {
                    if (a.getNamespace().equalsIgnoreCase("urn:perun:vo:attribute-def:core")) {
                        vo.setShortName(a.getValue());
                    }
                } else if (a.getFriendlyName().equalsIgnoreCase("description")) {
                    if (a.getNamespace().equalsIgnoreCase("urn:perun:group:attribute-def:core")) {
                        group.setDescription(a.getValue());
                    }
                } else if (a.getFriendlyName().equalsIgnoreCase("contactEmail")) {
                    if (a.getNamespace().equalsIgnoreCase("urn:perun:vo:attribute-def:def")) {
                        // set contact email
                        for (int n = 0; n < a.getValueAsJsArray().length(); n++) {
                            SafeHtmlBuilder s = new SafeHtmlBuilder();
                            if (n > 0) {
                                //others
                                s.appendHtmlConstant(voContact.getHTML().concat(", <a href=\"mailto:" + a.getValueAsJsArray().get(n) + "\">" + a.getValueAsJsArray().get(n) + "</a>"));
                            } else {
                                // first
                                s.appendHtmlConstant(voContact.getHTML().concat("<a href=\"mailto:" + a.getValueAsJsArray().get(n) + "\">" + a.getValueAsJsArray().get(n) + "</a>"));
                            }
                            voContact.setHTML(s.toSafeHtml());
                        }
                    }
                }
            }
            // store attrs
            vo.setAttributes(list);
            loadPerunPrincipal(events);
        }

        @Override
        public void onError(PerunError error) {
            // hides the loading box
            loadingBox.hide();
            RootLayoutPanel panel = RootLayoutPanel.get();
            panel.clear();
            panel.add(getErrorWidget(error));
        }
    });
    req.setHidden(true);
    req.retrieveData();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JSONObject(com.google.gwt.json.client.JSONObject) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) Initialize(cz.metacentrum.perun.webgui.json.registrarManager.Initialize)

Aggregations

JSONObject (com.google.gwt.json.client.JSONObject)1 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)1 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)1 Initialize (cz.metacentrum.perun.webgui.json.registrarManager.Initialize)1