Search in sources :

Example 1 with Fmri

use of com.sun.pkg.client.Fmri in project Payara by payara.

the class UpdateCenterHandlers method getUcList.

@Handler(id = "getUcList", input = { @HandlerInput(name = "state", type = String.class, required = true) }, output = { @HandlerOutput(name = "result", type = java.util.List.class) })
public static void getUcList(HandlerContext handlerCtx) {
    List result = new ArrayList();
    if (Boolean.TRUE.equals(GuiUtil.getSessionValue("_noNetwork"))) {
        handlerCtx.setOutputValue("result", result);
        return;
    }
    try {
        Image img = getUpdateCenterImage();
        if (img == null) {
            handlerCtx.setOutputValue("result", result);
            return;
        }
        String state = (String) handlerCtx.getInputValue("state");
        if (state.equals("update")) {
            handlerCtx.setOutputValue("result", getUpdateDisplayList(img, false));
            return;
        }
        List<Fmri> displayList = null;
        if (state.equals("installed"))
            displayList = getInstalledList(img);
        else if (state.equals("addOn"))
            displayList = getAddOnList(img);
        if (displayList != null) {
            for (Fmri fmri : displayList) {
                Map oneRow = new HashMap();
                try {
                    Manifest manifest = img.getManifest(fmri);
                    oneRow.put("selected", false);
                    oneRow.put("fmri", fmri);
                    oneRow.put("fmriStr", fmri.toString());
                    putInfo(oneRow, "pkgName", fmri.getName());
                    putInfo(oneRow, "version", getPkgVersion(fmri.getVersion()));
                    putInfo(oneRow, "newVersion", "");
                    putInfo(oneRow, "category", getCategory(manifest));
                    putInfo(oneRow, "pkgSize", getPkgSize(manifest));
                    oneRow.put("size", Integer.valueOf(manifest.getPackageSize()));
                    putInfo(oneRow, "auth", fmri.getAuthority());
                    String tooltip = manifest.getAttribute(PKG_SUMMARY);
                    if (GuiUtil.isEmpty(tooltip))
                        tooltip = manifest.getAttribute(DESC);
                    putInfo(oneRow, "tooltip", tooltip);
                    result.add(oneRow);
                } catch (Exception ex) {
                    GuiUtil.getLogger().info("getUcList(): " + ex.getLocalizedMessage());
                    if (GuiUtil.getLogger().isLoggable(Level.FINE)) {
                        ex.printStackTrace();
                    }
                }
            }
        }
    } catch (Exception ex1) {
        GuiUtil.getLogger().info("getUcList(): " + ex1.getLocalizedMessage());
        if (GuiUtil.getLogger().isLoggable(Level.FINE)) {
            ex1.printStackTrace();
        }
    }
    handlerCtx.setOutputValue("result", result);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Image(com.sun.pkg.client.Image) Manifest(com.sun.pkg.client.Manifest) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) Fmri(com.sun.pkg.client.Fmri) Handler(com.sun.jsftemplating.annotation.Handler)

Example 2 with Fmri

use of com.sun.pkg.client.Fmri in project Payara by payara.

the class UpdateCenterHandlers method getLicenseText.

// getLicenseText(selectedRows="#{selectedRows}" license=>$page{license});
@Handler(id = "getLicenseText", input = { @HandlerInput(name = "selectedRows", type = java.util.List.class, required = true) }, output = { @HandlerOutput(name = "license", type = String.class), @HandlerOutput(name = "hasLicense", type = Boolean.class) })
public static void getLicenseText(HandlerContext handlerCtx) {
    List obj = (List) handlerCtx.getInputValue("selectedRows");
    Image image = getUpdateCenterImage();
    List<Map> selectedRows = (List) obj;
    try {
        StringBuffer allLicense = new StringBuffer();
        for (Map oneRow : selectedRows) {
            Fmri fmri = (Fmri) oneRow.get("fmri");
            allLicense.append(getLicense(image, fmri));
        }
        handlerCtx.setOutputValue("license", "" + allLicense);
        handlerCtx.setOutputValue("hasLicense", (allLicense.length() > 0));
    } catch (Exception ex) {
        GuiUtil.handleException(handlerCtx, ex);
    // ex.printStackTrace();
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Image(com.sun.pkg.client.Image) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) Fmri(com.sun.pkg.client.Fmri) Handler(com.sun.jsftemplating.annotation.Handler)

Example 3 with Fmri

use of com.sun.pkg.client.Fmri in project Payara by payara.

the class UpdateCenterHandlers method getUpdateDisplayList.

// If countOnly is set to true,  return a List that contains only one Integer that specifies the # of updates.
// This is for displaying in the masthead
// If countOnly is set to false, it will go through each package that has update available and return a list
// suitable for displaying as a table row.
private static List getUpdateDisplayList(Image image, boolean countOnly) {
    List<Image.FmriState> installed = image.getInventory(null, false);
    Map<String, Fmri> updateListMap = new HashMap();
    List<String> nameList = new ArrayList();
    for (Image.FmriState fs : installed) {
        if (fs.upgradable) {
            Fmri fmri = fs.fmri;
            updateListMap.put(fmri.getName(), fmri);
            nameList.add(fmri.getName());
        }
    }
    List result = new ArrayList();
    String[] pkgsName = nameList.toArray(new String[nameList.size()]);
    try {
        Image.ImagePlan ip = image.makeInstallPlan(pkgsName, "list");
        Fmri[] proposed = ip.getProposedFmris();
        if (countOnly) {
            result.add(Integer.valueOf(proposed.length));
            return result;
        }
        for (Fmri newPkg : proposed) {
            Map oneRow = new HashMap();
            try {
                String name = newPkg.getName();
                Fmri oldPkg = updateListMap.get(name);
                Manifest manifest = image.getManifest(newPkg);
                int changedSize = manifest.getPackageSize() - image.getManifest(oldPkg).getPackageSize();
                oneRow.put("selected", false);
                oneRow.put("fmri", newPkg);
                oneRow.put("fmriStr", newPkg.toString());
                putInfo(oneRow, "pkgName", name);
                putInfo(oneRow, "newVersion", getPkgVersion(newPkg.getVersion()));
                putInfo(oneRow, "version", getPkgVersion(oldPkg.getVersion()));
                putInfo(oneRow, "category", getCategory(manifest));
                putInfo(oneRow, "pkgSize", convertSizeForDispay(changedSize));
                oneRow.put("size", Integer.valueOf(changedSize));
                putInfo(oneRow, "auth", newPkg.getAuthority());
                String tooltip = manifest.getAttribute(PKG_SUMMARY);
                if (GuiUtil.isEmpty(tooltip))
                    tooltip = manifest.getAttribute(DESC);
                putInfo(oneRow, "tooltip", tooltip);
                result.add(oneRow);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        if (countOnly) {
            List tmpL = new ArrayList();
            tmpL.add(Integer.valueOf(-1));
            return tmpL;
        }
    }
    GuiUtil.setSessionValue("_updateCountMsg", GuiUtil.getMessage(UpdateCenterHandlers.BUNDLE, "msg.updatesAvailable", new String[] { "" + result.size() }));
    return result;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Image(com.sun.pkg.client.Image) Manifest(com.sun.pkg.client.Manifest) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) Fmri(com.sun.pkg.client.Fmri)

Example 4 with Fmri

use of com.sun.pkg.client.Fmri in project Payara by payara.

the class UpdateCenterHandlers method getPkgDetailsInfo.

@Handler(id = "getPkgDetailsInfo", input = { @HandlerInput(name = "fmriStr", type = String.class, required = true), @HandlerInput(name = "auth", type = String.class, required = true) }, output = { @HandlerOutput(name = "details", type = java.util.Map.class) })
public static void getPkgDetailsInfo(HandlerContext handlerCtx) {
    String fmriStr = (String) handlerCtx.getInputValue("fmriStr");
    // Called by the intiPage and don't need to process.  When we can use beforeCreate to do this, we can remove this check.
    if (fmriStr == null) {
        handlerCtx.setOutputValue("details", new HashMap());
        return;
    }
    Fmri fmri = new Fmri(fmriStr);
    Map details = new HashMap();
    Image img = getUpdateCenterImage();
    try {
        details.put("pkgName", fmri.getName());
        details.put("uid", fmri.toString());
        details.put("version", getPkgVersion(fmri.getVersion()));
        details.put("date", fmri.getVersion().getPublishDate());
        details.put("auth", (String) handlerCtx.getInputValue("auth"));
        details.put("url", fmri.getURLPath());
        if (img != null) {
            Manifest manifest = img.getManifest(fmri);
            details.put("category", getCategory(manifest));
            details.put("bytes", "" + manifest.getPackageSize());
            details.put("pkgSize", getPkgSize(manifest));
            // look for description in the following order:
            // pkg.description, description_long, pkg.summary, description
            // since description_long and description has been deprecated.
            String desc = manifest.getAttribute(PKG_DESC);
            if (GuiUtil.isEmpty(desc)) {
                desc = manifest.getAttribute(DESC_LONG);
                if (GuiUtil.isEmpty(desc)) {
                    desc = manifest.getAttribute(PKG_SUMMARY);
                    if (GuiUtil.isEmpty(desc))
                        desc = manifest.getAttribute(DESC);
                }
            }
            details.put("desc", desc);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    handlerCtx.setOutputValue("details", details);
}
Also used : HashMap(java.util.HashMap) Image(com.sun.pkg.client.Image) Manifest(com.sun.pkg.client.Manifest) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) Fmri(com.sun.pkg.client.Fmri) Handler(com.sun.jsftemplating.annotation.Handler)

Example 5 with Fmri

use of com.sun.pkg.client.Fmri in project Payara by payara.

the class UpdateCenterHandlers method getAddOnList.

private static List<Fmri> getAddOnList(Image image) {
    List<String> installed = new ArrayList<String>();
    for (Image.FmriState each : image.getInventory(null, false)) {
        installed.add(each.fmri.getName());
    }
    String pAuth = image.getPreferredAuthorityName();
    SortedMap<String, Fmri> addOnMap = new TreeMap();
    for (Image.FmriState each : image.getInventory(null, true)) {
        Fmri fmri = each.fmri;
        // of this package is installed, then skip it.
        if (each.installed || installed.contains(fmri.getName())) {
            continue;
        }
        if (addOnMap.containsKey(fmri.getName())) {
            // We have seen this package name already. See if this
            // version should replace the saved version.
            Fmri saved = addOnMap.get(fmri.getName());
            if (supersedes(fmri, saved, pAuth)) {
                addOnMap.put(fmri.getName(), fmri);
            }
        } else {
            // We haven't seen this package name yet. Save fmri
            addOnMap.put(fmri.getName(), fmri);
        }
    }
    List<Fmri> result = new ArrayList();
    for (Fmri f : addOnMap.values()) {
        result.add(f);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Image(com.sun.pkg.client.Image) TreeMap(java.util.TreeMap) Fmri(com.sun.pkg.client.Fmri)

Aggregations

Fmri (com.sun.pkg.client.Fmri)5 Image (com.sun.pkg.client.Image)5 TreeMap (java.util.TreeMap)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 SortedMap (java.util.SortedMap)4 Handler (com.sun.jsftemplating.annotation.Handler)3 Manifest (com.sun.pkg.client.Manifest)3 List (java.util.List)3