Example usage for java.lang Long decode

List of usage examples for java.lang Long decode

Introduction

In this page you can find the example usage for java.lang Long decode.

Prototype

public static Long decode(String nm) throws NumberFormatException 

Source Link

Document

Decodes a String into a Long .

Usage

From source file:fr.gael.dhus.olingo.v1.Processor.java

@Override
public ODataResponse createEntityLink(PostUriInfo uri_info, InputStream content, String request_content_type,
        String content_type) throws ODataException {
    // Target of the link to create
    //EdmEntitySet link_target_es = uri_info.getTargetEntitySet();

    // Gets the entityset containing the navigation link to `link_target_es`
    EdmEntitySet target_es = getLinkFromES(new AdaptableUriInfo(uri_info));
    EdmEntityType target_et = target_es.getEntityType();

    fr.gael.dhus.database.object.User current_user = Security.getCurrentUser();

    AbstractEntitySet<?> es = Model.getEntitySet(target_es.getName());
    if (!es.isAuthorized(current_user)) {
        throw new NotAllowedException();
    }/*from  w  ww.  j  a va  2s  .  co  m*/

    // Check abilities and permissions
    if (!target_es.getName().equals(Model.USER.getName())
            && !target_es.getName().equals(Model.SCANNER.getName())) {
        throw new ODataException("EntitySet " + target_et.getName() + " cannot create links");
    }

    // Reads and parses the link
    String link = UriParsingUtils
            .extractResourcePath(EntityProvider.readLink(content_type, target_es, content));

    // Use Olingo's UriParser
    UriParser urip = RuntimeDelegate.getUriParser(getContext().getService().getEntityDataModel());
    List<PathSegment> path_segments = new ArrayList<>();
    StringTokenizer st = new StringTokenizer(link, "/");
    while (st.hasMoreTokens()) {
        path_segments.add(UriParser.createPathSegment(st.nextToken(), null));
    }

    UriInfo uilink = urip.parse(path_segments, Collections.<String, String>emptyMap());

    // get affected entity and create link
    String key = uri_info.getKeyPredicates().get(0).getLiteral();
    if (target_es.getName().equals(Model.USER.getName())) {
        User user = new User(key);
        user.createLink(uilink);
    } else if (target_es.getName().equals(Model.SCANNER.getName())) {
        Scanner scanner = Scanner.get(Long.decode(key));
        scanner.createLink(uilink);
    }

    // Empty answer with HTTP code 204: no content
    return ODataResponse.newBuilder().build();
}

From source file:org.jbpm.formModeler.components.editor.WysiwygFormEditor.java

protected Map fillFormFromForm(Map parameterMap) {
    Map m = new HashMap();
    String[] name = (String[]) parameterMap.get("name");
    String[] displayMode = (String[]) parameterMap.get("displayMode");
    String[] displayModeAligned = (String[]) parameterMap.get("displayModeAligned");
    String[] labelMode = (String[]) parameterMap.get("labelMode");

    String[] status = (String[]) parameterMap.get("status");
    String[] copyingFrom = (String[]) parameterMap.get("copyingFrom");

    if (status == null || status.length == 0) {
        status = new String[] { String.valueOf(FormManagerImpl.FORMSTATUS_NORMAL) };
    }/* ww  w. j a  v  a  2 s. com*/

    m.put("name", (name != null && name.length > 0) ? name[0] : null);
    m.put("displayModeAligned",
            (displayModeAligned != null && displayModeAligned.length > 0) ? displayModeAligned[0]
                    : Form.DISPLAY_MODE_NONE);
    m.put("displayMode", (displayMode != null && displayMode.length > 0) ? displayMode[0] : "default");
    m.put("labelMode", (labelMode != null && labelMode.length > 0) ? labelMode[0] : "undefined");
    m.put("status", Long.decode(status[0]));
    m.put("copyingFrom",
            (copyingFrom != null && !"".equals(copyingFrom[0].trim())) ? (Long.decode(copyingFrom[0])) : null);
    return m;
}

From source file:fr.gael.dhus.olingo.v1.Processor.java

@Override
public ODataResponse updateEntity(PutMergePatchUriInfo uri_info, InputStream content, String rq_content_type,
        boolean merge, String content_type) throws ODataException {
    EntityProviderReadProperties properties = EntityProviderReadProperties.init().mergeSemantic(merge).build();
    ODataEntry entry = EntityProvider.readEntry(rq_content_type, uri_info.getStartEntitySet(), content,
            properties);//w  w w .j a  va2s.  c  om

    fr.gael.dhus.database.object.User current_user = Security.getCurrentUser();

    EdmEntityType target_et = uri_info.getTargetEntitySet().getEntityType();
    try {
        String target_entity = target_et.getName();
        if (target_entity.equals(Model.SYNCHRONIZER.getEntityName())) {
            if (Model.SYNCHRONIZER.isAuthorized(current_user)) {
                long key = Long.decode(uri_info.getKeyPredicates().get(0).getLiteral());
                Synchronizer s = new Synchronizer(key);
                s.updateFromEntry(entry);
            } else {
                throw new NotAllowedException();
            }
        } else if (target_entity.equals(Model.USER.getEntityName())) {
            String key = uri_info.getKeyPredicates().get(0).getLiteral();
            User u = new User(key);
            if (u.isAuthorize(current_user)) {
                u.updateFromEntry(entry);
            } else {
                throw new NotAllowedException();
            }
        } else if (target_entity.equals(Model.INGEST.getEntityName())) {
            long key = Long.decode(uri_info.getKeyPredicates().get(0).getLiteral());
            Ingest i = Ingest.get(key);
            if (i == null) {
                throw new InvalidKeyException(String.valueOf(key), target_entity);
            }
            i.updateFromEntry(entry);
        } else if (target_entity.equals(Model.USER_SYNCHRONIZER.getEntityName())) {
            if (Model.USER_SYNCHRONIZER.isAuthorized(current_user)) {
                long key = Long.decode(uri_info.getKeyPredicates().get(0).getLiteral());
                UserSynchronizer s = new UserSynchronizer(key);
                s.updateFromEntry(entry);
            } else {
                throw new NotAllowedException();
            }
        } else if (target_entity.equals(Model.SCANNER.getEntityName())) {
            if (Model.SCANNER.isAuthorized(current_user)) {
                long id = Long.decode(uri_info.getKeyPredicates().get(0).getLiteral());
                Scanner scanner = Scanner.get(id);
                scanner.updateFromEntry(entry);
            }
        } else if (target_entity.equals(Model.EVENT.getEntityName())) {
            if (Model.EVENT.hasWritePermission(current_user)) {
                long key = Long.decode(uri_info.getKeyPredicates().get(0).getLiteral());
                Event event = new Event(key);
                event.updateFromEntry(entry);
            } else {
                throw new NotAllowedException();
            }
        } else if (target_entity.equals(Model.EVENT_SYNCHRONIZER.getEntityName())) {
            if (Model.EVENT_SYNCHRONIZER.isAuthorized(current_user)) {
                long key = Long.decode(uri_info.getKeyPredicates().get(0).getLiteral());
                EventSynchronizer eventSynchronizer = new EventSynchronizer(key);
                eventSynchronizer.updateFromEntry(entry);
            } else {
                throw new NotAllowedException();
            }
        } else {
            throw new NotImplementedException();
        }
    } catch (NullPointerException e) {
        return ODataResponse.status(HttpStatusCodes.NOT_FOUND).build();
    }

    return ODataResponse.status(HttpStatusCodes.NO_CONTENT).build();
}

From source file:org.jboss.dashboard.ui.components.DashboardFilterHandler.java

public synchronized boolean deserializeComponentData(String serializedData) throws Exception {
    // Load options and visible properties
    if (serializedData == null || serializedData.trim().length() == 0) {
        log.info("No data to deserialize.");
        return false;
    }/*from   ww w .j ava  2s.  c  o  m*/

    DOMParser parser = new DOMParser();
    parser.parse(new InputSource(new StringReader(serializedData)));
    Document doc = parser.getDocument();
    NodeList nodes = doc.getElementsByTagName("dashboard_filter");
    if (nodes.getLength() > 1) {
        log.error("Each dashboard filter component just can parse one <dashboard_filter>");
        return false;
    }
    if (nodes.getLength() == 0) {
        log.info("No data to deserialize.");
        return false;
    }

    boolean needsToSerializeAfter = false;
    serializedProperties = serializedData;
    Node rootNode = nodes.item(0);
    nodes = rootNode.getChildNodes();
    for (int x = 0; x < nodes.getLength(); x++) {
        Node node = nodes.item(x);
        if (node.getNodeName().equals("property")) {
            // Parse visible properties.
            String dataProviderCode = node.getAttributes().getNamedItem("providerCode").getNodeValue();
            String propertyId = node.getAttributes().getNamedItem("id").getNodeValue();
            String sectionId = null;
            boolean visible = false;
            NodeList subnodes = node.getChildNodes();
            for (int i = 0; i < subnodes.getLength(); i++) {
                Node subnode = subnodes.item(i);
                if (subnode.getNodeName().equals("section")) {
                    sectionId = subnode.getFirstChild().getNodeValue();
                }
                if (subnode.getNodeName().equals("visible")) {
                    visible = Boolean.valueOf(subnode.getFirstChild().getNodeValue()).booleanValue();
                }
            }
            Long lSectionId = sectionId != null ? Long.decode(sectionId) : null;
            DashboardFilterProperty filterProp = new DashboardFilterProperty(dataProviderCode, propertyId,
                    getFilter(), lSectionId, true);
            filterProp.setVisible(visible);
            if (filterProp.isPropertyAlive())
                properties.add(filterProp);
            else
                needsToSerializeAfter = true;
        } else if (node.getNodeName().equals("options")) {
            // Parse component options.
            NodeList options = node.getChildNodes();
            String showRefreshButton = null;
            String showPropertyNames = null;
            String showClearButton = null;
            String showApplyButton = null;
            String showSubmitOnChange = null;
            String showShortViewMode = null;
            String showLegend = null;
            String showAutoRefresh = null;
            for (int i = 0; i < options.getLength(); i++) {
                Node option = options.item(i);
                if (option.getNodeName().equals("showRefreshButton"))
                    showRefreshButton = option.getFirstChild().getNodeValue();
                if (option.getNodeName().equals("showPropertyNames"))
                    showPropertyNames = option.getFirstChild().getNodeValue();
                if (option.getNodeName().equals("showClearButton"))
                    showClearButton = option.getFirstChild().getNodeValue();
                if (option.getNodeName().equals("showApplyhButton"))
                    showApplyButton = option.getFirstChild().getNodeValue();
                if (option.getNodeName().equals("showSubmitOnChange"))
                    showSubmitOnChange = option.getFirstChild().getNodeValue();
                if (option.getNodeName().equals("shortViewMode"))
                    showShortViewMode = option.getFirstChild().getNodeValue();
                if (option.getNodeName().equals("showLegend"))
                    showLegend = option.getFirstChild().getNodeValue();
                if (option.getNodeName().equals("showAutoRefresh"))
                    showAutoRefresh = option.getFirstChild().getNodeValue();
            }
            this.showPropertyNames = Boolean.valueOf(showPropertyNames).booleanValue();
            this.showRefreshButton = Boolean.valueOf(showRefreshButton).booleanValue();
            this.showApplyButton = Boolean.valueOf(showApplyButton).booleanValue();
            this.showClearButton = Boolean.valueOf(showClearButton).booleanValue();
            this.showSubmitOnChange = Boolean.valueOf(showSubmitOnChange).booleanValue();
            this.isShortMode = Boolean.valueOf(showShortViewMode).booleanValue();
            this.showLegend = Boolean.valueOf(showLegend).booleanValue();
            this.showAutoRefresh = Boolean.valueOf(showAutoRefresh).booleanValue();

            // Enable auto-refresh if necessary on start.
            if (this.showAutoRefresh)
                setRefreshEnabled(true);
        }
    }
    return needsToSerializeAfter;
}

From source file:com.emergya.persistenceGeo.web.RestLayersAdminController.java

@RequestMapping(value = "/persistenceGeo/deleteLayerByLayerId/{layerId}", method = RequestMethod.POST)
public @ResponseBody Map<String, Object> DeleteLayerByLayerId(@PathVariable String layerId) {
    Map<String, Object> result = new HashMap<String, Object>();
    try {/*  www  .j a v a2 s.  co  m*/
        /*
        //TODO: Secure with logged user
        String username = ((UserDetails) SecurityContextHolder.getContext()
              .getAuthentication().getPrincipal()).getUsername(); 
         */
        Long idLayer = Long.decode(layerId);
        layerAdminService.deleteLayerById(idLayer);
        result.put(SUCCESS, true);
        result.put(ROOT, new HashMap<String, Object>());
    } catch (Exception e) {
        e.printStackTrace();
        result.put(SUCCESS, false);
        result.put(ROOT, "No se ha podido borrar la capa");
    }
    return result;
}

From source file:org.apache.hadoop.hbase.KEY.java

public int parseCommandLine(final String[] args) {
    // (but hopefully something not as painful as cli options).
    int errCode = 0;
    if (args.length < 1) {
        printUsage();//  ww w  . j a  v  a 2 s.  c  o  m
        return -1;
    }

    for (int i = 0; i < args.length; i++) {
        String cmd = args[i];
        if (cmd.equals("-h") || cmd.startsWith("--h")) {
            printUsage();
            break;
        }

        final String colnum = "--colnum=";
        if (cmd.startsWith(colnum)) {
            int val = Integer.parseInt(cmd.substring(colnum.length()));
            if (val <= 0 || val > this.MAX_COLUMN_NUM)
                val = this.DEFAULT_COLUMN_NUM;
            this.colNum = val;
            this.conf.setLong(KEY.OPTION_COLNUM, this.colNum);
            continue;
        }

        final String cf = "--cfnum=";
        if (cmd.startsWith(cf)) {
            int val = Integer.parseInt(cmd.substring(cf.length()));
            if (val <= 0 || val > this.MAX_FAMILY_NUM)
                val = this.DEFAULT_FAMILY_NUM;
            this.cfNum = val;
            this.conf.setInt(KEY.OPTION_CFNUM, this.cfNum);
            continue;
        }

        final String rows = "--rownum=";
        if (cmd.startsWith(rows)) {
            long val = Long.decode(cmd.substring(rows.length()));
            if (val < 0 || val > this.MAX_ROW_NUM)
                val = this.DEFAULT_ROW_NUM;
            this.rowNum = val;
            continue;
        }

        final String colsFormat = "--colsformat=";
        if (cmd.startsWith(colsFormat)) {
            this.coltypes = cmd.substring(colsFormat.length());
            continue;
        }

        final String regions = "--regions=";
        if (cmd.startsWith(regions)) {
            int val = Integer.parseInt(cmd.substring(regions.length()));
            if (val <= 0 || val > this.MAX_REGION_NUM)
                val = this.DEFAULT_REGION_NUMBER;
            this.regionNumber = val;
            continue;
        }

        final String enabledot = "--enabledot";
        if (cmd.startsWith(enabledot)) {
            this.createDotTable = true;
            continue;
        }

        final String usebulkload = "--usebulkload";
        if (cmd.startsWith(usebulkload)) {
            this.useBulkLoad = true;
            continue;
        }

        final String compressionOP = "--compression=";
        if (cmd.startsWith(compressionOP)) {
            String compressionCodec = cmd.substring(compressionOP.length());
            if (compressionCodec.equalsIgnoreCase("gz")) {
                this.compression = Compression.Algorithm.GZ;
            } else if (compressionCodec.equalsIgnoreCase("lzo")) {
                this.compression = Compression.Algorithm.LZO;
            } else if (compressionCodec.equalsIgnoreCase("snappy")) {
                this.compression = Compression.Algorithm.SNAPPY;
            } else {
                this.compression = Compression.Algorithm.NONE;
            }
            continue;
        }

        final String encodingOP = "--encoding=";
        if (cmd.startsWith(encodingOP)) {
            String encodingCodec = cmd.substring(encodingOP.length());
            if (encodingCodec.equalsIgnoreCase("fastdiff")) {
                this.encoding = DataBlockEncoding.FAST_DIFF;
            } else if (encodingCodec.equalsIgnoreCase("diff")) {
                this.encoding = DataBlockEncoding.DIFF;
            } else if (encodingCodec.equalsIgnoreCase("prefix")) {
                this.encoding = DataBlockEncoding.PREFIX;
            } else {
                this.encoding = DataBlockEncoding.NONE;
            }
            continue;
        }

        final String table = "--table=";
        if (cmd.startsWith(table)) {
            this.tableName = cmd.substring(table.length());
            continue;
        }
    }

    if (this.tableName == null) {
        printUsage("Please specify the table name");
        errCode = -2;
    }

    if (this.coltypes == null) {
        this.coltypes = "s";
        for (int j = 1; j < this.colNum; j++) {
            this.coltypes = this.coltypes.concat(",s");
        }
    }

    DataGenUtil dataGenUtil = new DataGenUtil();
    DataGenUtil.ColFormat[] colsFormat = dataGenUtil.parseColsFormat(this.coltypes);
    if (colsFormat.length != this.colNum) {
        System.err.println("colformat string : " + this.coltypes + " does not match colNum");
        errCode = -3;
    }

    this.conf.set(KEY.OPTION_COLSFORMAT, this.coltypes);

    this.baseRowNumber = 1L;
    while (this.baseRowNumber < this.rowNum) {
        this.baseRowNumber *= 10L;
    }

    this.conf.setLong(KEY.OPTION_BASEROWNUM, this.baseRowNumber);
    this.conf.setLong(KEY.OPTION_REGIONROWNUM, this.rowNum / this.regionNumber);

    this.conf.setBoolean(KEY.OPTION_USEBULKLOAD, useBulkLoad);

    System.out.println("cfnum = " + this.cfNum);
    System.out.println("colnum = " + this.colNum);
    System.out.println("colsFormat = " + colsFormat);
    System.out.println("rownum = " + this.rowNum);
    System.out.println("baseRowNumber = " + this.baseRowNumber);
    System.out.println("tablename = " + this.tableName);
    System.out.println("Presplit Region number = " + this.regionNumber);
    System.out.println("row per region = " + this.rowNum / this.regionNumber);
    System.out.println("Also create dot table = " + this.createDotTable);
    System.out.println("Data Block Encoding = " + this.encoding);
    System.out.println("Compression = " + this.compression);
    System.out.println("Use BulkLoad = " + this.useBulkLoad);
    return errCode;
}

From source file:fr.gael.dhus.olingo.v1.Processor.java

@Override
public ODataResponse deleteEntity(DeleteUriInfo uri_info, String content_type) throws ODataException {
    fr.gael.dhus.database.object.User current_user = Security.getCurrentUser();

    EdmEntityType target_et = uri_info.getTargetEntitySet().getEntityType();
    String target_name = target_et.getName();
    if (target_name.equals(Model.SYNCHRONIZER.getEntityName())) {
        if (Model.SYNCHRONIZER.isAuthorized(current_user)) {
            long key = Long.decode(uri_info.getKeyPredicates().get(0).getLiteral());
            Synchronizer.delete(key);//from w w w . j av a 2  s . co m
        } else {
            throw new NotAllowedException();
        }
    } else if (target_name.equals(Model.USER_SYNCHRONIZER.getEntityName())) {
        if (Model.USER_SYNCHRONIZER.isAuthorized(current_user)) {
            long key = Long.decode(uri_info.getKeyPredicates().get(0).getLiteral());
            Synchronizer.delete(key); // using the same method to delete
        } else {
            throw new NotAllowedException();
        }
    } else if (target_et.getName().equals(Model.PRODUCT.getEntityName())) {
        String uuid = uri_info.getKeyPredicates().get(0).getLiteral();
        Map<String, String> customQueryOptions = uri_info.getCustomQueryOptions();
        String cause = customQueryOptions.get("cause");
        String purgeInfo = customQueryOptions.get("purge");
        boolean purge = Boolean.parseBoolean(purgeInfo);
        Product.delete(uuid, cause, purge);
    } else if (target_et.getName().equals(Model.DELETEDPRODUCT.getEntityName())) {
        String uuid = uri_info.getKeyPredicates().get(0).getLiteral();
        DeletedProduct.delete(uuid);
    } else if (target_et.getName().equals(Model.INGEST.getEntityName())) {
        long key = Long.decode(uri_info.getKeyPredicates().get(0).getLiteral());
        Ingest.delete(key);
    } else if (target_et.getName().equals(Model.SCANNER.getEntityName())) {
        if (Model.SCANNER.isAuthorized(current_user)) {
            long id = Long.decode(uri_info.getKeyPredicates().get(0).getLiteral());
            Scanner.delete(id);
        } else {
            throw new NotAllowedException();
        }
    } else if (target_et.getName().equals(Model.EVENT.getEntityName())) {
        long key = Long.decode(uri_info.getKeyPredicates().get(0).getLiteral());
        Event.delete(key);
    } else if (target_et.getName().equals(Model.EVENT_SYNCHRONIZER.getEntityName())) {
        if (Model.EVENT_SYNCHRONIZER.isAuthorized(current_user)) {
            long key = Long.decode(uri_info.getKeyPredicates().get(0).getLiteral());
            Synchronizer.delete(key);
        } else {
            throw new NotAllowedException();
        }
    } else if (target_et.getName().equals(Model.USER.getEntityName())) {
        if (current_user.getRoles().contains(Role.USER_MANAGER)) {
            String username = uri_info.getKeyPredicates().get(0).getLiteral();
            User.delete(username);
        } else {
            throw new NotAllowedException();
        }
    } else {
        throw new NotImplementedException();
    }

    return ODataResponse.status(HttpStatusCodes.NO_CONTENT).build();
}

From source file:org.apache.cocoon.acting.AbstractValidatorAction.java

/**
 * Returns the parsed Long value./*from   ww  w. ja  v a2  s  .c  o  m*/
 */
private Long getLongValue(Object param, boolean is_string) throws ClassCastException, NumberFormatException {

    /* convert param to long */
    if (is_string) {
        String tmp = getStringValue(param);
        if (tmp == null) {
            return null;
        }
        return Long.decode(tmp);
    } else {
        return (Long) param;
    }
}

From source file:org.agnitas.backend.Data.java

/**
 * Fill already sent recipient in seen hashset for
 * recovery prupose//from   w  w  w  . j  a v a 2  s  .c o  m
 * @param seen the hashset to fill with seen customerIDs
 */
public void prefillRecipients(HashSet<Long> seen) throws Exception {
    if (isWorldMailing() || isRuleMailing() || isOnDemandMailing()) {
        File recovery = new File(metaDir, "recover-" + maildrop_status_id + ".list");

        if (recovery.exists()) {
            logging(Log.INFO, "recover", "Found recovery file " + recovery.getAbsolutePath());
            markToRemove(recovery.getAbsolutePath());

            FileInputStream in = new FileInputStream(recovery);
            byte[] content = new byte[(int) recovery.length()];

            in.read(content);
            in.close();
            String[] data = (new String(content, "US-ASCII")).split("\n");

            for (int n = 0; n < data.length; ++n) {
                if (data[n].length() > 0) {
                    seen.add(Long.decode(data[n]));
                }
            }
        }
    }
}