Example usage for java.lang Long intValue

List of usage examples for java.lang Long intValue

Introduction

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

Prototype

public int intValue() 

Source Link

Document

Returns the value of this Long as an int after a narrowing primitive conversion.

Usage

From source file:ProcessRequest.java

public void updateTicket(JSONObject recordObject) throws SQLException, JSONException {
    //check for ticket existence
    //check for ticket detail existence
    String valuesPortion = "";

    String ticketDate = null;//w  w w. ja  va  2 s  . co  m
    try {
        ticketDate = mDateFormat
                .format(new java.util.Date(recordObject.getLong(DbSingleton.TicketSchema.COLUMN_TICKET_DATE)));
    } catch (JSONException jsone) {
        ticketDate = recordObject.getString(DbSingleton.TicketSchema.COLUMN_TICKET_DATE);
    } finally {
        recordObject.put(DbSingleton.TicketSchema.COLUMN_TICKET_DATE, ticketDate);
    }

    String invoiceDate = null;
    try {
        invoiceDate = mDateFormat
                .format(new java.util.Date(recordObject.getLong(DbSingleton.TicketSchema.COLUMN_INVOICE_DATE)));
    } catch (JSONException jsone) {
        invoiceDate = recordObject.getString(DbSingleton.TicketSchema.COLUMN_INVOICE_DATE);
    } finally {
        recordObject.put(DbSingleton.TicketSchema.COLUMN_INVOICE_DATE, invoiceDate);
    }

    String voucherRedeemableDate = null;
    try {
        voucherRedeemableDate = mDateFormat.format(new java.util.Date(
                recordObject.getLong(DbSingleton.TicketSchema.COLUMN_VOUCHER_REDEEMABLE_DATE)));
    } catch (JSONException jsone) {
        voucherRedeemableDate = recordObject.getString(DbSingleton.TicketSchema.COLUMN_VOUCHER_REDEEMABLE_DATE);
    } finally {
        recordObject.put(DbSingleton.TicketSchema.COLUMN_VOUCHER_REDEEMABLE_DATE, voucherRedeemableDate);
    }

    String voucherExpirationDate = null;
    try {
        voucherExpirationDate = mDateFormat.format(new java.util.Date(
                recordObject.getLong(DbSingleton.TicketSchema.COLUMN_VOUCHER_EXPIRATION_DATE)));
    } catch (JSONException jsone) {
        voucherExpirationDate = recordObject.getString(DbSingleton.TicketSchema.COLUMN_VOUCHER_EXPIRATION_DATE);
    } finally {
        recordObject.put(DbSingleton.TicketSchema.COLUMN_VOUCHER_EXPIRATION_DATE, voucherExpirationDate);
    }

    String paymentDate = null;
    try {
        paymentDate = mDateFormat
                .format(new java.util.Date(recordObject.getLong(DbSingleton.TicketSchema.COLUMN_PAYMENT_DATE)));
    } catch (JSONException jsone) {
        paymentDate = recordObject.getString(DbSingleton.TicketSchema.COLUMN_PAYMENT_DATE);
    } finally {
        recordObject.put(DbSingleton.TicketSchema.COLUMN_PAYMENT_DATE, paymentDate);
    }

    String trailerLastTareDate = null;
    try {
        trailerLastTareDate = mDateFormat.format(new java.util.Date(
                recordObject.getLong(DbSingleton.TicketSchema.COLUMN_TRAILER_LAST_TARE_DATE)));
    } catch (JSONException jsone) {
        trailerLastTareDate = recordObject.getString(DbSingleton.TicketSchema.COLUMN_TRAILER_LAST_TARE_DATE);
    } finally {
        recordObject.put(DbSingleton.TicketSchema.COLUMN_TRAILER_LAST_TARE_DATE, trailerLastTareDate);
    }

    String truckLastTareDate = null;
    try {
        truckLastTareDate = mDateFormat.format(
                new java.util.Date(recordObject.getLong(DbSingleton.TicketSchema.COLUMN_TRUCK_LAST_TARE_DATE)));
    } catch (JSONException jsone) {
        truckLastTareDate = recordObject.getString(DbSingleton.TicketSchema.COLUMN_TRUCK_LAST_TARE_DATE);
    } finally {
        recordObject.put(DbSingleton.TicketSchema.COLUMN_TRUCK_LAST_TARE_DATE, truckLastTareDate);
    }

    recordObject.remove(DbSingleton.TicketSchema.COLUMN_LAST_MODIFIED);
    recordObject.put(DbSingleton.TicketSchema.COLUMN_LAST_MODIFIED, mDateFormat.format(new java.util.Date()));
    recordObject.remove("TMSRowGUID");

    //recordObject.remove(DbSingleton.TicketSchema.COLUMN_TICKET_NUMBER);
    //recordObject.put(DbSingleton.TicketSchema.COLUMN_TICKET_NUMBER, getNextTicketNumber());

    //get column names
    JsonParser parser = new JsonParser();
    JsonObject recordGson = parser.parse(recordObject.toString()).getAsJsonObject();
    Set<Map.Entry<String, JsonElement>> entrySet = recordGson.entrySet();
    Integer ticketID = null;

    //get values
    {
        Iterator<Map.Entry<String, JsonElement>> iterator = entrySet.iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, JsonElement> entry = iterator.next();
            if (entry.getKey().equals("metadata")) {
                //do nothing
            } else {
                JsonPrimitive value = entry.getValue().getAsJsonPrimitive();
                //System.out.println(entry.getKey()+" : "+value.getAsString());
                if (value.isString()) {
                    if (!valuesPortion.equals("")) {
                        valuesPortion += ",";
                    }
                    //System.out.println(entry.getKey()+" : '"+value.getAsString()+"'");
                    valuesPortion += entry.getKey() + "=";
                    valuesPortion += "'" + value.getAsString() + "'";
                } else if (value.isNumber()) {
                    if (value.getAsString().contains(".")) {
                        if (!valuesPortion.equals("")) {
                            valuesPortion += ",";
                        }
                        //System.out.println(entry.getKey()+" : "+(new Double(value.getAsDouble()).toString()));
                        valuesPortion += entry.getKey() + "=";
                        valuesPortion += new Double(value.getAsDouble()).toString();
                    } else {
                        //String ticketNumber = new Long(value.getAsLong()).toString();
                        Long val = new Long(value.getAsLong());
                        if (entry.getKey().equals(DbSingleton.TicketSchema.COLUMN_TICKET_ID)) {
                            ticketID = val.intValue();
                        } else {
                            if (!valuesPortion.equals("")) {
                                valuesPortion += ",";
                            }
                            //System.out.println(entry.getKey()+" : "+(new Long(value.getAsLong()).toString()));
                            valuesPortion += entry.getKey() + "=";
                            valuesPortion += val.toString();
                        }
                    }
                } else if (value.isBoolean()) {
                    if (!valuesPortion.equals("")) {
                        valuesPortion += ",";
                    }
                    //System.out.println(entry.getKey()+" : "+(new Boolean(value.getAsBoolean()).toString()));
                    if (value.getAsBoolean()) {
                        valuesPortion += entry.getKey() + "=";
                        valuesPortion += "1";
                    } else {
                        valuesPortion += entry.getKey() + "=";
                        valuesPortion += "0";
                    }
                }
            }
        }
    }

    //String insertQuery = "INSERT INTO "+DbSingleton.TICKET_DETAIL_TABLE_NAME+"("+columnsPortion+") VALUES ("+valuesPortion+")";
    if (ticketID == null) {
        throw new SQLException("no ticket id found!");
    }
    String updateQuery = "UPDATE " + DbSingleton.TICKET_TABLE_NAME + " SET " + valuesPortion + " WHERE "
            + DbSingleton.TicketSchema.COLUMN_TICKET_ID + "=" + ticketID;
    //String identQuery = "SELECT IDENT_CURRENT ('"+DbSingleton.TICKET_DETAIL_TABLE_NAME+"') AS TicketDetailID";

    executeQuery(updateQuery);
}

From source file:ProcessRequest.java

public void updateTicketDetail(Integer ticketID, JSONObject recordObject) throws SQLException, JSONException {

    //check for ticket detail existence
    String valuesPortion = "";

    recordObject.remove(DbSingleton.TicketDetailSchema.COLUMN_LAST_MODIFIED);
    recordObject.put(DbSingleton.TicketDetailSchema.COLUMN_LAST_MODIFIED,
            mDateFormat.format(new java.util.Date()));
    recordObject.remove("TMSRowGUID");

    String grossDate = null;/*from   ww w .  j  a  v  a  2 s .  c  o m*/
    try {
        grossDate = mDateFormat.format(
                new java.util.Date(recordObject.getLong(DbSingleton.TicketDetailSchema.COLUMN_GROSS_LBS_DT)));
    } catch (JSONException jsone) {
        grossDate = recordObject.getString(DbSingleton.TicketDetailSchema.COLUMN_GROSS_LBS_DT);
    } finally {
        recordObject.put(DbSingleton.TicketDetailSchema.COLUMN_GROSS_LBS_DT, grossDate);
    }

    String grossALTDate = null;
    try {
        grossALTDate = mDateFormat.format(new java.util.Date(
                recordObject.getLong(DbSingleton.TicketDetailSchema.COLUMN_ALT_GROSS_LBS_DT)));
    } catch (JSONException jsone) {
        grossALTDate = recordObject.getString(DbSingleton.TicketDetailSchema.COLUMN_ALT_GROSS_LBS_DT);
    } finally {
        recordObject.put(DbSingleton.TicketDetailSchema.COLUMN_ALT_GROSS_LBS_DT, grossALTDate);
    }

    String tareDate = null;
    try {
        tareDate = mDateFormat.format(
                new java.util.Date(recordObject.getLong(DbSingleton.TicketDetailSchema.COLUMN_TARE_LBS_DT)));
    } catch (JSONException jsone) {
        tareDate = recordObject.getString(DbSingleton.TicketDetailSchema.COLUMN_TARE_LBS_DT);
    } finally {
        recordObject.put(DbSingleton.TicketDetailSchema.COLUMN_TARE_LBS_DT, tareDate);
    }

    String tareALTDate = null;
    try {
        tareALTDate = mDateFormat.format(new java.util.Date(
                recordObject.getLong(DbSingleton.TicketDetailSchema.COLUMN_ALT_TARE_LBS_DT)));
    } catch (JSONException jsone) {
        tareALTDate = recordObject.getString(DbSingleton.TicketDetailSchema.COLUMN_ALT_TARE_LBS_DT);
    } finally {
        recordObject.put(DbSingleton.TicketDetailSchema.COLUMN_ALT_TARE_LBS_DT, tareALTDate);
    }

    String deductDate = null;
    try {
        deductDate = mDateFormat.format(
                new java.util.Date(recordObject.getLong(DbSingleton.TicketDetailSchema.COLUMN_DEDUCT_LBS_DT)));
    } catch (JSONException jsone) {
        deductDate = recordObject.getString(DbSingleton.TicketDetailSchema.COLUMN_DEDUCT_LBS_DT);
    } finally {
        recordObject.put(DbSingleton.TicketDetailSchema.COLUMN_DEDUCT_LBS_DT, deductDate);
    }

    String deductALTDate = null;
    try {
        deductALTDate = mDateFormat.format(new java.util.Date(
                recordObject.getLong(DbSingleton.TicketDetailSchema.COLUMN_ALT_DEDUCT_LBS_DT)));
    } catch (JSONException jsone) {
        deductALTDate = recordObject.getString(DbSingleton.TicketDetailSchema.COLUMN_ALT_DEDUCT_LBS_DT);
    } finally {
        recordObject.put(DbSingleton.TicketDetailSchema.COLUMN_ALT_DEDUCT_LBS_DT, deductALTDate);
    }

    //recordObject.remove(DbSingleton.TicketSchema.COLUMN_TICKET_NUMBER);
    //recordObject.put(DbSingleton.TicketSchema.COLUMN_TICKET_NUMBER, getNextTicketNumber());

    //get column names
    JsonParser parser = new JsonParser();
    JsonObject recordGson = parser.parse(recordObject.toString()).getAsJsonObject();
    Set<Map.Entry<String, JsonElement>> entrySet = recordGson.entrySet();
    Integer ticketDetailID = null;

    //get values
    {
        Iterator<Map.Entry<String, JsonElement>> iterator = entrySet.iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, JsonElement> entry = iterator.next();
            if (entry.getKey().equals("metadata")) {
                //do nothing
            } else {
                JsonPrimitive value = entry.getValue().getAsJsonPrimitive();
                //System.out.println(entry.getKey()+" : "+value.getAsString());
                if (value.isString()) {
                    if (!valuesPortion.equals("")) {
                        valuesPortion += ",";
                    }
                    //System.out.println(entry.getKey()+" : '"+value.getAsString()+"'");
                    valuesPortion += entry.getKey() + "=";
                    valuesPortion += "'" + value.getAsString() + "'";
                } else if (value.isNumber()) {
                    if (value.getAsString().contains(".")) {
                        if (!valuesPortion.equals("")) {
                            valuesPortion += ",";
                        }
                        //System.out.println(entry.getKey()+" : "+(new Double(value.getAsDouble()).toString()));
                        valuesPortion += entry.getKey() + "=";
                        valuesPortion += new Double(value.getAsDouble()).toString();
                    } else {
                        Long val = new Long(value.getAsLong());
                        if (entry.getKey().equals(DbSingleton.TicketDetailSchema.COLUMN_TICKET_DETAIL_ID)) {
                            ticketDetailID = val.intValue();
                        } else {
                            if (!valuesPortion.equals("")) {
                                valuesPortion += ",";
                            }
                            //System.out.println(entry.getKey()+" : "+(new Long(value.getAsLong()).toString()));
                            valuesPortion += entry.getKey() + "=";
                            //String ticketNumber = new Long(value.getAsLong()).toString();
                            valuesPortion += val.toString();
                        }
                    }
                } else if (value.isBoolean()) {
                    if (!valuesPortion.equals("")) {
                        valuesPortion += ",";
                    }
                    //System.out.println(entry.getKey()+" : "+(new Boolean(value.getAsBoolean()).toString()));
                    if (value.getAsBoolean()) {
                        valuesPortion += entry.getKey() + "=";
                        valuesPortion += "1";
                    } else {
                        valuesPortion += entry.getKey() + "=";
                        valuesPortion += "0";
                    }
                }
            }
        }
    }

    //String insertQuery = "INSERT INTO "+DbSingleton.TICKET_DETAIL_TABLE_NAME+"("+columnsPortion+") VALUES ("+valuesPortion+")";
    if (ticketDetailID == null) {
        throw new SQLException("no ticket detail id found!");
    }
    String updateQuery = "UPDATE " + DbSingleton.TICKET_DETAIL_TABLE_NAME + " SET " + valuesPortion + " WHERE "
            + DbSingleton.TicketDetailSchema.COLUMN_TICKET_DETAIL_ID + "=" + ticketDetailID;
    //String identQuery = "SELECT IDENT_CURRENT ('"+DbSingleton.TICKET_DETAIL_TABLE_NAME+"') AS TicketDetailID";

    executeQuery(updateQuery);
}

From source file:com.microsoft.azure.storage.blob.CloudBlobClientEncryptionTests.java

private void validateRangeDecryption(BlobType type, int blobSize, Long blobOffset, Long length,
        Integer verifyLength) throws StorageException, URISyntaxException, InvalidKeyException,
        NoSuchAlgorithmException, NoSuchPaddingException, IOException {
    byte[] buffer = BlobTestHelper.getRandomBuffer(blobSize);

    CloudBlob blob = null;//www  .j a v a2s.  c  o  m
    if (type == BlobType.BLOCK_BLOB) {
        blob = this.container.getBlockBlobReference("blockblob");
    } else if (type == BlobType.PAGE_BLOB) {
        blob = this.container.getPageBlobReference("pageblob");
    } else if (type == BlobType.APPEND_BLOB) {
        blob = this.container.getAppendBlobReference("appendblob");
    }

    // Create the Key to be used for wrapping.
    SymmetricKey aesKey = TestHelper.getSymmetricKey();

    // Create the encryption policy to be used for upload.
    BlobEncryptionPolicy uploadPolicy = new BlobEncryptionPolicy(aesKey, null);

    // Set the encryption policy on the request options.
    BlobRequestOptions options = new BlobRequestOptions();
    options.setEncryptionPolicy(uploadPolicy);

    // Upload the encrypted contents to the blob.
    ByteArrayInputStream stream = new ByteArrayInputStream(buffer);
    blob.upload(stream, blobSize, null, options, null);

    // Download a range in the encrypted blob.
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    blob.downloadRange(blobOffset, length, outputStream, null, options, null);

    // Compare that the decrypted contents match the input data.
    byte[] outputArray = outputStream.toByteArray();

    if (length != null) {
        if (verifyLength != null) {
            assertEquals(verifyLength.intValue(), outputArray.length);
        } else {
            assertEquals(length.intValue(), outputArray.length);
        }
    }

    for (int i = 0; i < outputArray.length; i++) {
        int bufferOffset = (int) (blobOffset != null ? blobOffset : 0);
        assertEquals(buffer[bufferOffset + i], outputArray[i]);
    }
}

From source file:edu.harvard.iq.dvn.core.web.servlet.FileDownloadServlet.java

public File saveRemoteFile(StudyFile file, FileDownloadObject fileDownload) {

    File tabFile = null;//from  w w  w  .j a  va  2  s . c  om
    File dtFile = null;

    try {
        // save the incoming stream as a temp file

        // temp data file that stores incoming data
        // (meaning, the entire file, containing all variables;
        // tab-delimited or fixed-field.)

        dtFile = File.createTempFile("tempDataFile.", ".dat");

        InputStream in = fileDownload.getInputStream();
        OutputStream out = new BufferedOutputStream(new FileOutputStream(dtFile));

        int bufsize;
        byte[] bffr = new byte[4 * 8192];

        while ((bufsize = in.read(bffr)) != -1) {
            out.write(bffr, 0, bufsize);
        }

        in.close();
        out.close();

        // Check the resulting file

        if (dtFile.exists()) {

            // if it exists, and the file is tab-delimited, we can
            // proceed sending it to the R batch server for conversion;
            // if however, it is fixed-field, it has to be converted
            // to the tab-delimited format first. That we do by
            // requesting a "subsetting" of the file for all of its
            // variables:

            if (file.getFileType() != null && file.getFileType().equals("text/tab-separated-values")) {
                tabFile = dtFile;
            } else {
                // must be a fixed-field file.

                // create yet another temporary file to store the
                // results of jcut subsetting:

                tabFile = File.createTempFile("tempTabFile.", ".tab");

                // subsetting:

                Long noRecords = ((TabularDataFile) file).getDataTable().getRecordsPerCase();
                Map<Long, List<List<Integer>>> varMetaSet = getSubsettingMetaData(noRecords);
                DvnNewJavaFieldCutter fc = new DvnNewJavaFieldCutter(varMetaSet);

                try {
                    fc.cutColumns(dtFile, noRecords.intValue(), 0, "\t", tabFile.getAbsolutePath());
                } catch (Exception e) {
                    // TODO: actually, it would be nice to be able to
                    // tell if we've failed to download the remote file
                    // or failed to convert it.
                    // (otherwise there's not even any point in catching
                    // this exception separately here!)
                    return null;
                }
            }
        }
    } catch (Exception ex) {
        // TODO: should probably create and save an error message here.
        // "failed to download (as opposed to failed to convert").
    }

    if (tabFile != null && tabFile.exists()) {
        return tabFile;
    }

    return null;
}

From source file:it.govpay.web.rs.dars.anagrafica.ruoli.RuoliHandler.java

@Override
public Ruolo creaEntry(InputStream is, UriInfo uriInfo, BasicBD bd)
        throws WebApplicationException, ConsoleException {
    String methodName = "creaEntry " + this.titoloServizio;
    Ruolo entry = null;//from  w  w w  .  java 2  s  . co  m

    String funzionalita_A_PPAId = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".funzionalita_A_PPA.id");
    String domini_A_PPAId = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".domini_A_PPA.id");
    String diritti_A_PPAId = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".diritti_A_PPA.id");

    String funzionalita_A_CONId = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".funzionalita_A_CON.id");
    String domini_A_CONId = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".domini_A_CON.id");
    String diritti_A_CONId = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".diritti_A_CON.id");

    String funzionalita_A_APPId = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".funzionalita_A_APP.id");
    String domini_A_APPId = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".domini_A_APP.id");
    String diritti_A_APPId = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".diritti_A_APP.id");

    String funzionalita_A_USRId = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".funzionalita_A_USR.id");
    String domini_A_USRId = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".domini_A_USR.id");
    String diritti_A_USRId = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".diritti_A_USR.id");

    String funzionalita_G_PAGId = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".funzionalita_G_PAG.id");
    String domini_G_PAGId = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".domini_G_PAG.id");
    String diritti_G_PAGId = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".diritti_G_PAG.id");
    String admin_G_PAGId = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".admin_G_PAG.id");

    String funzionalita_G_RNDId = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".funzionalita_G_RND.id");
    String domini_G_RNDId = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".domini_G_RND.id");
    String diritti_G_RNDId = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".diritti_G_RND.id");

    String funzionalita_GDEId = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".funzionalita_GDE.id");
    String domini_GDEId = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".domini_GDE.id");
    String diritti_GDEId = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".diritti_GDE.id");

    String funzionalita_MANId = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".funzionalita_MAN.id");
    String funzionalita_STATId = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".funzionalita_STAT.id");

    try {
        this.log.info("Esecuzione " + methodName + " in corso...");
        // Operazione consentita solo ai ruoli con diritto di scrittura
        this.darsService.checkDirittiServizioScrittura(bd, this.funzionalita);

        JsonConfig jsonConfig = new JsonConfig();

        Map<String, Class<?>> classMap = new HashMap<String, Class<?>>();
        classMap.put(domini_A_PPAId, Long.class);
        classMap.put(diritti_A_PPAId, Long.class);
        classMap.put(domini_A_CONId, Long.class);
        classMap.put(diritti_A_CONId, Long.class);
        classMap.put(domini_A_APPId, Long.class);
        classMap.put(diritti_A_APPId, Long.class);
        classMap.put(domini_A_USRId, Long.class);
        classMap.put(diritti_A_USRId, Long.class);
        classMap.put(domini_G_PAGId, Long.class);
        classMap.put(diritti_G_PAGId, Long.class);
        classMap.put(domini_G_RNDId, Long.class);
        classMap.put(diritti_G_RNDId, Long.class);
        classMap.put(domini_GDEId, Long.class);
        classMap.put(diritti_GDEId, Long.class);
        jsonConfig.setClassMap(classMap);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Utils.copy(is, baos);

        baos.flush();
        baos.close();

        JSONObject jsonObjectRuolo = JSONObject.fromObject(baos.toString());

        List<Acl> lstAclDominiFunzionalita_A_PPA = new ArrayList<Acl>();

        if (jsonObjectRuolo.getBoolean(funzionalita_A_PPAId)) {
            JSONArray jsonDomini = jsonObjectRuolo.getJSONArray(domini_A_PPAId);
            // diritti
            Long diritti_A_PPA = jsonObjectRuolo.getLong(diritti_A_PPAId);

            for (int i = 0; i < jsonDomini.size(); i++) {
                long idDominio = jsonDomini.getLong(i);

                Acl acl = new Acl();
                acl.setTipo(Tipo.DOMINIO);
                acl.setServizio(Servizio.Anagrafica_PagoPa);
                acl.setDiritti(diritti_A_PPA.intValue());
                if (idDominio > 0) {
                    acl.setIdDominio(idDominio);
                    lstAclDominiFunzionalita_A_PPA.add(acl);
                } else {
                    lstAclDominiFunzionalita_A_PPA.clear();
                    lstAclDominiFunzionalita_A_PPA.add(acl);
                    break;
                }
            }
        }
        // rimuovo gli oggetti della parte Funzionalita_A_PPA
        jsonObjectRuolo.remove(funzionalita_A_PPAId);
        jsonObjectRuolo.remove(domini_A_PPAId);
        jsonObjectRuolo.remove(diritti_A_PPAId);

        List<Acl> lstAclDominiFunzionalita_A_CON = new ArrayList<Acl>();

        if (jsonObjectRuolo.getBoolean(funzionalita_A_CONId)) {
            JSONArray jsonDomini = jsonObjectRuolo.getJSONArray(domini_A_CONId);
            // diritti
            Long diritti_A_CON = jsonObjectRuolo.getLong(diritti_A_CONId);

            for (int i = 0; i < jsonDomini.size(); i++) {
                long idDominio = jsonDomini.getLong(i);

                Acl acl = new Acl();
                acl.setTipo(Tipo.DOMINIO);
                acl.setServizio(Servizio.Anagrafica_Contabile);
                acl.setDiritti(diritti_A_CON.intValue());
                if (idDominio > 0) {
                    acl.setIdDominio(idDominio);
                    lstAclDominiFunzionalita_A_CON.add(acl);
                } else {
                    lstAclDominiFunzionalita_A_CON.clear();
                    lstAclDominiFunzionalita_A_CON.add(acl);
                    break;
                }
            }
        }
        // rimuovo gli oggetti della parte Funzionalita_A_CON
        jsonObjectRuolo.remove(funzionalita_A_CONId);
        jsonObjectRuolo.remove(domini_A_CONId);
        jsonObjectRuolo.remove(diritti_A_CONId);

        List<Acl> lstAclDominiFunzionalita_A_APP = new ArrayList<Acl>();

        if (jsonObjectRuolo.getBoolean(funzionalita_A_APPId)) {
            JSONArray jsonDomini = jsonObjectRuolo.getJSONArray(domini_A_APPId);
            // diritti
            Long diritti_A_APP = jsonObjectRuolo.getLong(diritti_A_APPId);

            for (int i = 0; i < jsonDomini.size(); i++) {
                long idDominio = jsonDomini.getLong(i);

                Acl acl = new Acl();
                acl.setTipo(Tipo.DOMINIO);
                acl.setServizio(Servizio.Anagrafica_Applicazioni);
                acl.setDiritti(diritti_A_APP.intValue());
                if (idDominio > 0) {
                    acl.setIdDominio(idDominio);
                    lstAclDominiFunzionalita_A_APP.add(acl);
                } else {
                    lstAclDominiFunzionalita_A_APP.clear();
                    lstAclDominiFunzionalita_A_APP.add(acl);
                    break;
                }
            }
        }
        // rimuovo gli oggetti della parte Funzionalita_A_APP
        jsonObjectRuolo.remove(funzionalita_A_APPId);
        jsonObjectRuolo.remove(domini_A_APPId);
        jsonObjectRuolo.remove(diritti_A_APPId);

        List<Acl> lstAclDominiFunzionalita_A_USR = new ArrayList<Acl>();

        if (jsonObjectRuolo.getBoolean(funzionalita_A_USRId)) {
            JSONArray jsonDomini = jsonObjectRuolo.getJSONArray(domini_A_USRId);
            // diritti
            Long diritti_A_USR = jsonObjectRuolo.getLong(diritti_A_USRId);

            for (int i = 0; i < jsonDomini.size(); i++) {
                long idDominio = jsonDomini.getLong(i);

                Acl acl = new Acl();
                acl.setTipo(Tipo.DOMINIO);
                acl.setServizio(Servizio.Anagrafica_Utenti);
                acl.setDiritti(diritti_A_USR.intValue());
                if (idDominio > 0) {
                    acl.setIdDominio(idDominio);
                    lstAclDominiFunzionalita_A_USR.add(acl);
                } else {
                    lstAclDominiFunzionalita_A_USR.clear();
                    lstAclDominiFunzionalita_A_USR.add(acl);
                    break;
                }
            }
        }
        // rimuovo gli oggetti della parte Funzionalita_A_USR
        jsonObjectRuolo.remove(funzionalita_A_USRId);
        jsonObjectRuolo.remove(domini_A_USRId);
        jsonObjectRuolo.remove(diritti_A_USRId);

        List<Acl> lstAclDominiFunzionalita_G_PAG = new ArrayList<Acl>();

        if (jsonObjectRuolo.getBoolean(funzionalita_G_PAGId)) {
            JSONArray jsonDomini = jsonObjectRuolo.getJSONArray(domini_G_PAGId);
            boolean admin = jsonObjectRuolo.getBoolean(admin_G_PAGId);
            // diritti
            Long diritti_G_PAG = jsonObjectRuolo.getLong(diritti_G_PAGId);

            for (int i = 0; i < jsonDomini.size(); i++) {
                long idDominio = jsonDomini.getLong(i);

                Acl acl = new Acl();
                acl.setTipo(Tipo.DOMINIO);
                acl.setServizio(Servizio.Gestione_Pagamenti);
                acl.setDiritti(diritti_G_PAG.intValue());
                acl.setAdmin(admin);
                if (idDominio > 0) {
                    acl.setIdDominio(idDominio);
                    lstAclDominiFunzionalita_G_PAG.add(acl);
                } else {
                    lstAclDominiFunzionalita_G_PAG.clear();
                    lstAclDominiFunzionalita_G_PAG.add(acl);
                    break;
                }
            }
        }
        // rimuovo gli oggetti della parte Funzionalita_G_PAG
        jsonObjectRuolo.remove(funzionalita_G_PAGId);
        jsonObjectRuolo.remove(domini_G_PAGId);
        jsonObjectRuolo.remove(diritti_G_PAGId);
        jsonObjectRuolo.remove(admin_G_PAGId);

        List<Acl> lstAclDominiFunzionalita_G_RND = new ArrayList<Acl>();

        if (jsonObjectRuolo.getBoolean(funzionalita_G_RNDId)) {
            JSONArray jsonDomini = jsonObjectRuolo.getJSONArray(domini_G_RNDId);
            // diritti
            Long diritti_G_RND = jsonObjectRuolo.getLong(diritti_G_RNDId);

            for (int i = 0; i < jsonDomini.size(); i++) {
                long idDominio = jsonDomini.getLong(i);

                Acl acl = new Acl();
                acl.setTipo(Tipo.DOMINIO);
                acl.setServizio(Servizio.Gestione_Rendicontazioni);
                acl.setDiritti(diritti_G_RND.intValue());
                if (idDominio > 0) {
                    acl.setIdDominio(idDominio);
                    lstAclDominiFunzionalita_G_RND.add(acl);
                } else {
                    lstAclDominiFunzionalita_G_RND.clear();
                    lstAclDominiFunzionalita_G_RND.add(acl);
                    break;
                }
            }
        }
        // rimuovo gli oggetti della parte Funzionalita_G_RND
        jsonObjectRuolo.remove(funzionalita_G_RNDId);
        jsonObjectRuolo.remove(domini_G_RNDId);
        jsonObjectRuolo.remove(diritti_G_RNDId);

        List<Acl> lstAclDominiFunzionalita_GDE = new ArrayList<Acl>();

        if (jsonObjectRuolo.getBoolean(funzionalita_GDEId)) {
            JSONArray jsonDomini = jsonObjectRuolo.getJSONArray(domini_GDEId);
            // diritti
            Long diritti_GDE = jsonObjectRuolo.getLong(diritti_GDEId);

            for (int i = 0; i < jsonDomini.size(); i++) {
                long idDominio = jsonDomini.getLong(i);

                Acl acl = new Acl();
                acl.setTipo(Tipo.DOMINIO);
                acl.setServizio(Servizio.Giornale_Eventi);
                acl.setDiritti(diritti_GDE.intValue());
                if (idDominio > 0) {
                    acl.setIdDominio(idDominio);
                    lstAclDominiFunzionalita_GDE.add(acl);
                } else {
                    lstAclDominiFunzionalita_GDE.clear();
                    lstAclDominiFunzionalita_GDE.add(acl);
                    break;
                }
            }
        }
        // rimuovo gli oggetti della parte Funzionalita_GDE
        jsonObjectRuolo.remove(funzionalita_GDEId);
        jsonObjectRuolo.remove(domini_GDEId);
        jsonObjectRuolo.remove(diritti_GDEId);

        List<Acl> lstAclDominiFunzionalita_MAN = new ArrayList<Acl>();

        if (jsonObjectRuolo.getBoolean(funzionalita_MANId)) {
            int diritti_MAN = Ruolo.DIRITTI_LETTURA;
            Acl acl = new Acl();
            acl.setTipo(Tipo.DOMINIO);
            acl.setServizio(Servizio.Manutenzione);
            acl.setDiritti(diritti_MAN);
            lstAclDominiFunzionalita_MAN.add(acl);
        }
        // rimuovo gli oggetti della parte Funzionalita_MAN
        jsonObjectRuolo.remove(funzionalita_MANId);

        List<Acl> lstAclDominiFunzionalita_STAT = new ArrayList<Acl>();

        if (jsonObjectRuolo.getBoolean(funzionalita_STATId)) {
            int diritti_STAT = Ruolo.DIRITTI_LETTURA;
            Acl acl = new Acl();
            acl.setTipo(Tipo.DOMINIO);
            acl.setServizio(Servizio.Statistiche);
            acl.setDiritti(diritti_STAT);
            lstAclDominiFunzionalita_STAT.add(acl);
        }
        // rimuovo gli oggetti della parte Funzionalita_STAT
        jsonObjectRuolo.remove(funzionalita_STATId);

        jsonConfig.setRootClass(Ruolo.class);
        entry = (Ruolo) JSONObject.toBean(jsonObjectRuolo, jsonConfig);

        // colleziono gli acl
        entry.setAcls(lstAclDominiFunzionalita_A_PPA);
        entry.getAcls().addAll(lstAclDominiFunzionalita_A_CON);
        entry.getAcls().addAll(lstAclDominiFunzionalita_A_APP);
        entry.getAcls().addAll(lstAclDominiFunzionalita_A_USR);
        entry.getAcls().addAll(lstAclDominiFunzionalita_G_PAG);
        entry.getAcls().addAll(lstAclDominiFunzionalita_G_RND);
        entry.getAcls().addAll(lstAclDominiFunzionalita_GDE);
        entry.getAcls().addAll(lstAclDominiFunzionalita_MAN);
        entry.getAcls().addAll(lstAclDominiFunzionalita_STAT);

        this.log.info("Esecuzione " + methodName + " completata.");
        return entry;
    } catch (WebApplicationException e) {
        throw e;
    } catch (Exception e) {
        throw new ConsoleException(e);
    }
}

From source file:com.redhat.rhn.frontend.xmlrpc.channel.software.ChannelSoftwareHandler.java

/**
 * Returns the number of available subscriptions for the given channel
 * @param loggedInUser The current user//from   w ww . jav a2 s. c o m
 * @param channelLabel Label of channel whose details are sought.
 * @return the number of available subscriptions for the given channel
 * @throws NoSuchChannelException thrown if no channel is found.
 *
 * @xmlrpc.doc Returns the number of available subscriptions for the given channel
 * @xmlrpc.param #session_key()
 * @xmlrpc.param #param_desc("string", "channelLabel", "channel to query")
 * @xmlrpc.returntype int number of available subscriptions for the given channel
 */
public int availableEntitlements(User loggedInUser, String channelLabel) throws NoSuchChannelException {

    Channel c = lookupChannelByLabel(loggedInUser, channelLabel);
    Long cnt = ChannelManager.getAvailableEntitlements(loggedInUser.getOrg(), c);
    if (cnt == null) {
        return 0;
    }
    return cnt.intValue();
}

From source file:com.skratchdot.electribe.model.esx.impl.SampleImpl.java

/**
 * @param file// w  w w  .j  a va  2s.  c  om
 * @throws EsxException
 */
protected SampleImpl(File file) throws EsxException {
    super();
    init();

    // Declare our streams and formats
    AudioFormat audioFormatEncoded;
    AudioFormat audioFormatDecoded;
    AudioInputStream audioInputStreamEncoded;
    AudioInputStream audioInputStreamDecoded;

    try {
        // Initialize our streams and formats
        audioInputStreamEncoded = AudioSystem.getAudioInputStream(file);
        audioFormatEncoded = audioInputStreamEncoded.getFormat();
        audioFormatDecoded = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
                audioFormatEncoded.getSampleRate(), 16, audioFormatEncoded.getChannels(),
                audioFormatEncoded.getChannels() * 2, audioFormatEncoded.getSampleRate(), true);
        audioInputStreamDecoded = AudioSystem.getAudioInputStream(audioFormatDecoded, audioInputStreamEncoded);

        // We have a decoded stereo audio stream
        // Now we need to get the stream info into a list we can manipulate
        byte[] audioData = new byte[4096];
        int nBytesRead = 0;
        long nTotalBytesRead = 0;
        List<Byte> audioDataListChannel1 = new ArrayList<Byte>();
        List<Byte> audioDataListChannel2 = new ArrayList<Byte>();
        boolean isAudioDataStereo = false;

        // Set isAudioDataStereo
        if (audioFormatEncoded.getChannels() == 1) {
            isAudioDataStereo = false;
        } else if (audioFormatEncoded.getChannels() == 2) {
            isAudioDataStereo = true;
        } else {
            throw new EsxException("Sample has too many channels: " + file.getAbsolutePath());
        }

        // Convert stream to list. This needs to be optimized. Converting
        // a byte at a time is probably too slow...
        while (nBytesRead >= 0) {
            nBytesRead = audioInputStreamDecoded.read(audioData, 0, audioData.length);

            // If we aren't at the end of the stream
            if (nBytesRead > 0) {
                for (int i = 0; i < nBytesRead; i++) {
                    // MONO
                    if (!isAudioDataStereo) {
                        audioDataListChannel1.add(audioData[i]);
                        audioDataListChannel2.add(audioData[i]);
                    }
                    // STEREO (LEFT)
                    else if (nTotalBytesRead % 4 < 2) {
                        audioDataListChannel1.add(audioData[i]);
                    }
                    // STEREO (RIGHT)
                    else {
                        audioDataListChannel2.add(audioData[i]);
                    }

                    // Update the total amount of bytes we've read
                    nTotalBytesRead++;
                }
            }

            // Throw Exception if sample is too big
            if (nTotalBytesRead > EsxUtil.MAX_SAMPLE_MEM_IN_BYTES) {
                throw new EsxException("Sample is too big: " + file.getAbsolutePath());
            }
        }

        // Set member variables
        int frameLength = audioDataListChannel1.size() / 2;
        this.setNumberOfSampleFrames(frameLength);
        this.setEnd(frameLength - 1);
        this.setLoopStart(frameLength - 1);
        this.setSampleRate((int) audioFormatEncoded.getSampleRate());
        this.setAudioDataChannel1(EsxUtil.listToByteArray(audioDataListChannel1));
        this.setAudioDataChannel2(EsxUtil.listToByteArray(audioDataListChannel2));
        this.setStereoOriginal(isAudioDataStereo);

        // Set calculated Sample Tune (from Sample Rate)
        SampleTune newSampleTune = EsxFactory.eINSTANCE.createSampleTune();
        float newFloat = newSampleTune.calculateSampleTuneFromSampleRate(this.getSampleRate());
        newSampleTune.setValue(newFloat);
        this.setSampleTune(newSampleTune);

        // Set name
        String newSampleName = new String();
        newSampleName = StringUtils.left(StringUtils.trim(file.getName()), 8);
        this.setName(newSampleName);

        // Attempt to set loopStart and End from .wav smpl chunk
        if (file.getAbsolutePath().toLowerCase().endsWith(".wav")) {
            try {
                RIFFWave riffWave = WavFactory.eINSTANCE.createRIFFWave(file);
                ChunkSampler chunkSampler = (ChunkSampler) riffWave
                        .getFirstChunkByEClass(WavPackage.Literals.CHUNK_SAMPLER);
                if (chunkSampler != null && chunkSampler.getSampleLoops().size() > 0) {
                    SampleLoop sampleLoop = chunkSampler.getSampleLoops().get(0);
                    Long tempLoopStart = sampleLoop.getStart();
                    Long tempLoopEnd = sampleLoop.getEnd();
                    if (tempLoopStart < this.getEnd() && tempLoopStart >= 0) {
                        this.setLoopStart(tempLoopStart.intValue());
                    }
                    if (tempLoopEnd < this.getEnd() && tempLoopEnd > this.getLoopStart()) {
                        this.setEnd(tempLoopEnd.intValue());
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    } catch (UnsupportedAudioFileException e) {
        e.printStackTrace();
        throw new EsxException("Invalid audio file: " + file.getAbsolutePath());
    } catch (IOException e) {
        e.printStackTrace();
        throw new EsxException("Invalid audio file: " + file.getAbsolutePath());
    } catch (Exception e) {
        e.printStackTrace();
        throw new EsxException("Invalid audio file: " + file.getAbsolutePath());
    }
}

From source file:com.mirth.connect.client.ui.DashboardPanel.java

public synchronized void updateTableHighlighting() {
    // MIRTH-2301
    // Since we are using addHighlighter here instead of using setHighlighters, we need to remove the old ones first.
    dashboardTable.setHighlighters();//from w w w.java 2  s .  c  o m

    // Add the highlighters. Always add the error highlighter.
    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        Highlighter highlighter = HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR,
                UIConstants.BACKGROUND_COLOR);
        dashboardTable.addHighlighter(highlighter);
    }

    HighlightPredicate queuedHighlighterPredicate = new HighlightPredicate() {
        public boolean isHighlighted(Component renderer, ComponentAdapter adapter) {
            if (adapter.column == dashboardTable.getColumnViewIndex(QUEUED_COLUMN_NAME)) {
                Long value = (Long) dashboardTable.getValueAt(adapter.row, adapter.column);

                if (value != null && value.longValue() > 0) {
                    return true;
                }
            }
            return false;
        }
    };

    dashboardTable.addHighlighter(new ColorHighlighter(queuedHighlighterPredicate, new Color(240, 230, 140),
            Color.BLACK, new Color(240, 230, 140), Color.BLACK));

    HighlightPredicate errorHighlighterPredicate = new HighlightPredicate() {

        public boolean isHighlighted(Component renderer, ComponentAdapter adapter) {
            if (adapter.column == dashboardTable.getColumnViewIndex(ERROR_COLUMN_NAME)) {
                Long value = (Long) dashboardTable.getValueAt(adapter.row, adapter.column);

                if (value != null && value.longValue() > 0) {
                    return true;
                }
            }
            return false;
        }
    };

    Highlighter errorHighlighter = new ColorHighlighter(errorHighlighterPredicate, Color.PINK, Color.BLACK,
            Color.PINK, Color.BLACK);
    dashboardTable.addHighlighter(errorHighlighter);

    HighlightPredicate revisionDeltaHighlighterPredicate = new HighlightPredicate() {
        public boolean isHighlighted(Component renderer, ComponentAdapter adapter) {
            if (adapter.column == dashboardTable.getColumnViewIndex(DEPLOYED_REVISION_DELTA_COLUMN_NAME)) {
                Integer value = (Integer) dashboardTable.getValueAt(adapter.row, adapter.column);

                if (value != null && value.intValue() > 0) {
                    return true;
                }

                TreePath path = dashboardTable.getPathForRow(adapter.row);
                if (path != null) {
                    AbstractDashboardTableNode dashboardTableNode = (AbstractDashboardTableNode) path
                            .getLastPathComponent();
                    if (!dashboardTableNode.isGroupNode()) {
                        DashboardStatus status = dashboardTableNode.getDashboardStatus();
                        if (status.getCodeTemplatesChanged() != null && status.getCodeTemplatesChanged()) {
                            return true;
                        }
                    }
                }
            }
            return false;
        }
    };

    dashboardTable.addHighlighter(new ColorHighlighter(revisionDeltaHighlighterPredicate,
            new Color(255, 204, 0), Color.BLACK, new Color(255, 204, 0), Color.BLACK));

    HighlightPredicate lastDeployedHighlighterPredicate = new HighlightPredicate() {
        public boolean isHighlighted(Component renderer, ComponentAdapter adapter) {
            if (adapter.column == dashboardTable.getColumnViewIndex(LAST_DEPLOYED_COLUMN_NAME)) {
                Calendar checkAfter = Calendar.getInstance();
                checkAfter.add(Calendar.MINUTE, -2);

                Object value = dashboardTable.getValueAt(adapter.row, adapter.column);

                if (value != null && value instanceof Calendar && ((Calendar) value).after(checkAfter)) {
                    return true;
                }
            }
            return false;
        }
    };

    dashboardTable.addHighlighter(new ColorHighlighter(lastDeployedHighlighterPredicate,
            new Color(240, 230, 140), Color.BLACK, new Color(240, 230, 140), Color.BLACK));
}

From source file:au.org.theark.study.model.dao.StudyDao.java

public List<OtherID> getPersonOtherIDList(Long personID) throws ArkSystemException {
    List<OtherID> personOtherIDList = getSession().createCriteria(OtherID.class)
            .add(Restrictions.eq(Constants.PERSON_PERSON_ID, personID)).list();
    log.info("Number of otherIDs fetched " + personOtherIDList.size() + "Person ID " + personID.intValue());

    if (personOtherIDList.isEmpty()) {
        log.error("this person has no other IDs; " + personID);
    }//from  w w w .  j  av  a2s.  c  om
    log.info("Number of OtherID items retrieved for person ID " + personID + " " + personOtherIDList.size());
    return personOtherIDList;
}