Search in sources :

Example 1 with ImportEntityModel

use of com.sun.identity.console.federation.model.ImportEntityModel in project OpenAM by OpenRock.

the class ImportEntityViewBean method handleButton1Request.

/**
     * Handles upload entity button request. There are two fields on this page:
     * one for standard metadata and the other for extended. The standard is
     * required.
     *
     * @param event Request invocation event
     * @throws ModelControlException
     */
public void handleButton1Request(RequestInvocationEvent event) throws ModelControlException {
    ImportEntityModel model = (ImportEntityModel) getModel();
    Map data = new HashMap(6);
    String realm = (String) getDisplayFieldValue(model.REALM_NAME);
    data.put(model.REALM_NAME, realm);
    String radioMeta = (String) getDisplayFieldValue("radioMeta");
    String meta = (radioMeta.equals("url")) ? (String) getDisplayFieldValue("tfMetadataFileURL") : (String) getDisplayFieldValue("tfMetadataFile");
    String radioExtended = (String) getDisplayFieldValue("radioExtended");
    String extended = (radioExtended.equals("url")) ? (String) getDisplayFieldValue("tfExtendeddataFileURL") : (String) getDisplayFieldValue("tfExtendeddataFile");
    if ((meta == null) || (meta.length() == 0)) {
        psModel.setErrorProperty("standardFileNameProperty", true);
        setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.input.error", "import.entity.missing.metadata");
        forwardTo();
    } else {
        data.put(ImportEntityModel.STANDARD_META, meta);
        if ((extended != null) || (extended.trim().length() > 0)) {
            data.put(ImportEntityModel.EXTENDED_META, extended);
        }
        try {
            model.importEntity(data);
            StringBuilder buff = new StringBuilder();
            // build the success message.
            // don't need the realm name in the message so remove it first.
            data.remove(ImportEntityModel.REALM_NAME);
            for (Iterator i = data.keySet().iterator(); i.hasNext(); ) {
                String key = (String) i.next();
                String value = (String) data.get(key);
                if ((value != null) && (value.length() > 0)) {
                    String val = (String) data.get(key);
                    if (val.startsWith("http")) {
                        if (buff.length() > 0) {
                            buff.append(", ");
                        }
                        buff.append(val);
                    } else {
                        int idx = val.lastIndexOf("<!-- ");
                        if (idx != -1) {
                            int idx1 = val.lastIndexOf(" -->");
                            if (idx1 != -1) {
                                val = val.substring(idx + 5, idx1);
                            }
                        }
                        if (buff.length() > 0) {
                            buff.append(", ");
                        }
                        buff.append(val);
                    }
                }
            }
            String message = "";
            if (buff.length() > 0) {
                Object[] params = { buff.toString() };
                message = MessageFormat.format(model.getLocalizedString("import.entity.metadata.success"), params);
            }
            // set the message in the main view
            setPageSessionAttribute(FederationViewBean.MESSAGE_TEXT, message);
            FederationViewBean vb = (FederationViewBean) getViewBean(FederationViewBean.class);
            passPgSessionMap(vb);
            vb.forwardTo(getRequestContext());
        } catch (AMConsoleException ame) {
            debug.warning("ImportEntityViewBean.handleButton1req ", ame);
            setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", ame.getMessage());
            forwardTo();
        }
    }
}
Also used : HashMap(java.util.HashMap) Iterator(java.util.Iterator) ImportEntityModel(com.sun.identity.console.federation.model.ImportEntityModel) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ImportEntityModel

use of com.sun.identity.console.federation.model.ImportEntityModel in project OpenAM by OpenRock.

the class ImportEntityViewBean method populateRealmData.

private void populateRealmData() {
    Set realmNames = Collections.EMPTY_SET;
    ImportEntityModel model = (ImportEntityModel) getModel();
    try {
        realmNames = model.getRealmNames("/", "*");
        CCDropDownMenu menu = (CCDropDownMenu) getChild(ImportEntityModel.REALM_NAME);
        OptionList sortedList = createOptionList(realmNames);
        OptionList optList = new OptionList();
        int size = sortedList.size();
        for (int i = 0; i < size; i++) {
            String name = sortedList.getValue(i);
            optList.add(getPath(name), name);
        }
        menu.setOptions(optList);
    } catch (AMConsoleException e) {
        debug.warning("ImportEntityViewBean.populateRealmData ", e);
        setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", "import.entity.populaterealmdata.error");
    }
}
Also used : Set(java.util.Set) ImportEntityModel(com.sun.identity.console.federation.model.ImportEntityModel) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) CCDropDownMenu(com.sun.web.ui.view.html.CCDropDownMenu) OptionList(com.iplanet.jato.view.html.OptionList)

Aggregations

AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)2 ImportEntityModel (com.sun.identity.console.federation.model.ImportEntityModel)2 OptionList (com.iplanet.jato.view.html.OptionList)1 CCDropDownMenu (com.sun.web.ui.view.html.CCDropDownMenu)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Set (java.util.Set)1