Example usage for java.lang Integer longValue

List of usage examples for java.lang Integer longValue

Introduction

In this page you can find the example usage for java.lang Integer longValue.

Prototype

public long longValue() 

Source Link

Document

Returns the value of this Integer as a long after a widening primitive conversion.

Usage

From source file:org.openmeetings.app.data.conference.Roommanagement.java

private boolean checkRoomShouldByDeleted(long orgId, List<Integer> organisations) throws Exception {
    for (Iterator<Integer> it = organisations.iterator(); it.hasNext();) {
        Integer key = it.next();
        Long storedOrgId = key.longValue();
        if (storedOrgId.equals(orgId))
            return true;
    }/* w  w w  .  j  av a  2  s .c o m*/
    return false;
}

From source file:org.openmeetings.app.data.conference.Roommanagement.java

private Long updateRoomOrganisations(List<Integer> organisations, Rooms room) throws Exception {
    List<Rooms_Organisation> roomOrganisations = this.getOrganisationsByRoom(3, room.getRooms_id());

    List<Long> roomsToAdd = new LinkedList<Long>();
    List<Long> roomsToDel = new LinkedList<Long>();

    for (Iterator<Integer> it = organisations.iterator(); it.hasNext();) {
        Integer key = it.next();
        Long orgIdToAdd = key.longValue();
        if (!this.checkRoomAlreadyInOrg(orgIdToAdd, roomOrganisations))
            roomsToAdd.add(orgIdToAdd);//  w  w  w. j  a  v a 2s .c  o  m
    }

    for (Iterator<Rooms_Organisation> it = roomOrganisations.iterator(); it.hasNext();) {
        Rooms_Organisation rOrganisation = it.next();
        Long orgIdToDel = rOrganisation.getOrganisation().getOrganisation_id();
        if (!this.checkRoomShouldByDeleted(orgIdToDel, organisations))
            roomsToDel.add(orgIdToDel);
    }

    // log.error("updateRoomOrganisations roomsToAdd: "+roomsToAdd.size());
    // log.error("updateRoomOrganisations roomsToDel: "+roomsToDel.size());

    for (Iterator<Long> it = roomsToAdd.iterator(); it.hasNext();) {
        Long orgIdToAdd = it.next();
        this.addRoomToOrganisation(3, room.getRooms_id(), orgIdToAdd);
    }
    for (Iterator<Long> it = roomsToDel.iterator(); it.hasNext();) {
        Long orgToDel = it.next();
        this.deleteRoomFromOrganisationByRoomAndOrganisation(room.getRooms_id(), orgToDel);
    }

    return new Long(1);
}

From source file:OSFFM_ORC.FederationActionManager.java

/**
 *
 * @param mapContainer//  ww  w.ja  va2 s  .c  o m
 * @param sClient
 * @param fedsdnURL
 * @return
 * @throws WSException
 * @throws JSONException
 * @author gtricomi
 */
private String checkTenantandInsertFEDSDN(FednetsLink mapContainer, Site sClient, String fedsdnURL, DBMongo m)
        throws WSException, JSONException, Exception {
    Response r = sClient.getAllSite(fedsdnURL);
    JSONArray ja = new JSONArray(r.readEntity(String.class));
    LinkedHashMap<String, OpenstackInfoContainer> CloudId_To_OIC = mapContainer.getCloudId_To_OIC();
    LinkedHashMap<String, JSONObject> tmpSiteList = new LinkedHashMap<String, JSONObject>();
    JSONArray inner = new JSONArray();
    String tenant = null;
    String tenant_password = null;
    String result = "";
    //for (int i = 0; i < ja.length(); i++) {
    //JSONObject jo = (JSONObject) ja.get(i);

    Set siteNameSet = new HashSet();
    //=new HashSet();
    for (int i = 0; i < ja.length(); i++) {
        JSONObject jo = (JSONObject) ja.get(i);
        /*String siteIdToCheck = (String) jo.get("id");
        String siteNameToCheck = (String) jo.get("name");
        siteSet.add(siteIdToCheck+"@@@@::::@@@@"+siteNameToCheck);*/
        //siteSet.add((String) jo.get("name"));
        tmpSiteList.put((String) jo.get("name"), jo);
    }

    Iterator it = CloudId_To_OIC.keySet().iterator();
    while (it.hasNext()) {
        String siteNameToCheck = (String) it.next();
        if ((tmpSiteList.containsKey(siteNameToCheck))) {
            try {

                OpenstackInfoContainer oik = (OpenstackInfoContainer) CloudId_To_OIC.get(siteNameToCheck);
                if (oik == null) {
                    String siteUsernameToCheck = "oneadmin";
                    String sitePasswordToCheck = "opennebulaone";
                    String credentials = siteUsernameToCheck + ":" + sitePasswordToCheck;
                    String user_id_insite = "1";
                    JSONObject inner_jo = new JSONObject("{\"site_id\" :\"ONE\",\"user_id_in_site\":\""
                            + user_id_insite + "\" ,\"credentials\":\"" + credentials + "\"}");
                    tenant = "review";
                    tenant_password = sitePasswordToCheck;
                } else {
                    String siteUsernameToCheck = oik.getTenant() + "@@@" + oik.getUser();
                    String sitePasswordToCheck = oik.getPassword();

                    String credentials = siteUsernameToCheck + ":" + sitePasswordToCheck;
                    KeystoneTest key = new KeystoneTest(oik.getTenant(), oik.getUser(), oik.getPassword(),
                            oik.getEndpoint());
                    String user_id_insite = null;
                    try {
                        user_id_insite = key.getTenantId(oik.getTenant());
                    } catch (Exception e) {
                        user_id_insite = "0";
                    }
                    //>>>BEACON 03/07/2017: statically insert 0, but need to be checked !!!

                    String siteIdToCheck = ((Integer) ((JSONObject) tmpSiteList.get(siteNameToCheck)).get("id"))
                            .toString();
                    JSONObject inner_jo = new JSONObject(
                            "{\"site_id\" :\"" + siteIdToCheck + "\",\"user_id_in_site\":\"" + user_id_insite
                                    + "\" ,\"credentials\":\"" + credentials + "\"}");
                    inner.put(inner_jo);

                    tenant = oik.getTenant();

                    //03/07/2017: federation password for the tenant is set equal to the openstack site !!!
                    tenant_password = sitePasswordToCheck;
                }
            } catch (Exception e) {
                LOGGER.error(
                        "Exception occurred in \"Valid Site\" field entry.\nSite skipped: " + siteNameToCheck);

            }
        }
    }

    //03/07/2017: verify username management like structure "NotManagedUser@userFederation@UME" !!!
    System.out.println(inner.toString());
    JSONObject tenant_jo = new JSONObject("{\"name\" :\"" + tenant + "\",\"password\":\"" + tenant_password
            + "\" ,\"type\":\"admin\",\"valid_sites\": " + inner.toString(0) + "}");
    // m.insertTenantTables(tenant, tenant_jo.toString());

    //03-07-2017 : hardcoded credential for tenant
    Tenant t = new Tenant(tenant, tenant_password);//"root","fedsdn");//
    boolean ok = false;
    for (int k = 0; k < inner.length(); k++) {
        try {
            System.out.println(tenant_jo.toString(0));
            r = t.updateTen(tenant_jo, tenant, fedsdnURL);//createTen(tenant_jo, fedsdnURL);//
            /*oggetto restituito:
            {
            "id": 7,
            "name": "TESTAGOSTO2",
            "password": "pass1",
            "type": "admin",
            "valid_sites": [
              {
                "tenant_id": 7,
                "site_id": 2,
                "user_id_in_site": "28",
                "credentials": "admin@admin:prova",
                "token": "86734b78980"
              }
            ]
              }
                    
             */
            String respon = r.readEntity(String.class);
            if ((respon.contains("Tenant ")) && (respon.contains("updated."))) {
                respon = respon.substring(respon.indexOf("Tenant"));
                respon = respon.replace("Tenant ", "");
                respon = respon.replace(" updated.\"\n]", "");
                Integer rid = new Integer(respon);
                r = t.getInfoTenant(fedsdnURL, rid.longValue());
                respon = r.readEntity(String.class);
            } else {
                throw new Exception("Something in the site insertion process isn't working fine.");
            }
            JSONObject resp = new JSONObject(respon);
            JSONObject entry = new JSONObject();
            String fedsdntenid = ((Integer) resp.remove("id")).toString();
            result = fedsdntenid;
            entry.put("tenantID", fedsdntenid);
            entry.put("tenantEntry", resp);
            m.insertTenantTables(tenant, entry.toString(0));
        } catch (WSException ex) {
            LOGGER.error("Exception is occurred in checkTenantFEDSDN for tenant: " + tenant + "\n" + ex);
            ok = false;
        }
        ok = true;
        if (ok) {
            break;
        } else if (k == 3) {
            LOGGER.error("Something going wrong! It's Impossible add site on FEDSDN");
            throw new Exception("Something in the site insertion process isn't working fine."); //03/07/2017: inserito per bloccare il flusso nel caso in cui qualche sito non venga inserito !!!
        }
    }

    return result;
}

From source file:org.oscarehr.casemgmt.service.CaseManagementManager.java

public List<AccessType> getAccessRight(String providerNo, String demoNo, String programId) {
    List<Integer> progList = new ArrayList<Integer>();

    if (programId == null) {
        for (Object o : demographicDao.getProgramIdByDemoNo(demoNo)) {
            progList.add((Integer) o);
        }/*w  w  w  . j  a  va  2  s. co  m*/
    } else {
        progList.add(Integer.valueOf(programId));
    }

    if (progList.isEmpty()) {
        return null;
    }

    List<AccessType> rt = new ArrayList<AccessType>();
    Iterator<Integer> itr = progList.iterator();

    while (itr.hasNext()) {
        Integer pId = itr.next();

        List<ProgramProvider> ppList = programProviderDao.getProgramProviderByProviderProgramId(providerNo,
                pId.longValue());
        List<ProgramAccess> paList = programAccessDAO.getAccessListByProgramId(pId.longValue());

        for (int i = 0; i < ppList.size(); i++) {
            ProgramProvider pp = ppList.get(i);
            // add default role access
            List<DefaultRoleAccess> arList = roleProgramAccessDAO.getDefaultAccessRightByRole(pp.getRoleId());
            for (int j = 0; j < arList.size(); j++) {
                DefaultRoleAccess ar = arList.get(j);
                addrt(rt, ar.getAccess_type());
            }
            for (int k = 0; k < paList.size(); k++) {
                ProgramAccess pa = paList.get(k);
                if (pa.isAllRoles()) {
                    addrt(rt, pa.getAccessType());
                } else if (roleInAccess(pp.getRoleId(), pa)) {
                    addrt(rt, pa.getAccessType());
                }
            }
        }
    }

    return rt;
}

From source file:service.actions.OrderSearch.java

private Long getLong(Object value) {
    if (value == null) {
        return null;
    } else {//from w w  w.  j a  v a2  s  .c  om
        if (value instanceof Long) {
            return (Long) value;
        } else if (value instanceof BigInteger) {
            BigInteger bi = (BigInteger) value;
            return bi.longValue();
        } else if (value instanceof Integer) {
            Integer i = (Integer) value;
            return i.longValue();
        }
    }
    return null;
}

From source file:org.sakaiproject.sitestats.impl.StatsUpdateManagerImpl.java

private void doUpdateSiteVisitsObjects(Session session, Collection<SiteVisits> o,
        Map<UniqueVisitsKey, Integer> map) {
    if (o == null)
        return;/*from   w  w w . j  a  v a 2  s  .c  om*/
    List<SiteVisits> objects = new ArrayList<SiteVisits>(o);
    Collections.sort(objects);
    Iterator<SiteVisits> i = objects.iterator();
    while (i.hasNext()) {
        SiteVisits eUpdate = i.next();
        SiteVisits eExisting = null;
        String eExistingSiteId = null;
        try {
            Criteria c = session.createCriteria(SiteVisitsImpl.class);
            c.add(Expression.eq("siteId", eUpdate.getSiteId()));
            c.add(Expression.eq("date", eUpdate.getDate()));
            try {
                eExisting = (SiteVisits) c.uniqueResult();
            } catch (HibernateException ex) {
                try {
                    List events = c.list();
                    if ((events != null) && (events.size() > 0)) {
                        LOG.debug("More than 1 result when unique result expected.", ex);
                        eExisting = (SiteVisits) c.list().get(0);
                    } else {
                        LOG.debug("No result found", ex);
                        eExisting = null;
                    }
                } catch (Exception ex3) {
                    eExisting = null;
                }
            } catch (Exception ex2) {
                LOG.warn("Probably ddbb error when loading data at java object", ex2);
            }
            if (eExisting == null) {
                eExisting = eUpdate;
            } else {
                eExisting.setTotalVisits(eExisting.getTotalVisits() + eUpdate.getTotalVisits());
            }
            Integer mapUV = map.get(new UniqueVisitsKey(eExisting.getSiteId(), eExisting.getDate()));
            eExisting.setTotalUnique(mapUV == null ? 1 : mapUV.longValue());

            eExistingSiteId = eExisting.getSiteId();
        } catch (Exception ex) {
            LOG.warn("Failed to event:" + eUpdate.getId(), ex);
        }
        if ((eExistingSiteId != null) && (eExistingSiteId.trim().length() > 0))
            session.saveOrUpdate(eExisting);
    }
}

From source file:org.sakaiproject.evaluation.logic.EvalEmailsLogicImpl.java

public String[] sendConsolidatedReminderNotifications(JobStatusReporter jobStatusReporter, String jobId) {
    // need to figure out selection criteria for Consolidated-Reminder Notifications:
    // admin settings and individual eval settings determine whether available emails should be sent.
    // admin settings indicate how frequently and at what time of day reminders should be sent. 
    // We can tell whether a reminder has been sent (once eval is Active) by whether the 
    // EvalAssignUser.reminderEmailSent column is null (no email sent) or contains a date (indicating
    // the date and approximate time when the email was sent to that user). 

    // If available email is being sent, the first reminder should be n days later (where n is the frequency
    // of sending reminders).  Otherwise, the first reminder should be sent the next time reminders are sent 
    // after the eval becomes Active.  Reminders should be repeated every n days.

    Integer batchSize = (Integer) this.settings.get(EvalSettings.EMAIL_BATCH_SIZE);
    if (batchSize == null || batchSize < MIN_BATCH_SIZE) {
        batchSize = MIN_BATCH_SIZE;// ww w .ja v  a2s  .c o  m
    }
    Integer waitInterval = (Integer) this.settings.get(EvalSettings.EMAIL_WAIT_INTERVAL);
    if (waitInterval == null || waitInterval < 0) {
        waitInterval = 0;
    }

    Boolean availableEmailEnabled = (Boolean) this.settings
            .get(EvalSettings.CONSOLIDATED_EMAIL_NOTIFY_AVAILABLE);
    if (availableEmailEnabled == null) {
        availableEmailEnabled = false;
    }

    Integer reminderFrequency = (Integer) this.settings.get(EvalSettings.SINGLE_EMAIL_REMINDER_DAYS);
    if (reminderFrequency == null) {
        // assume daily reminders if not specified
        reminderFrequency = 1;
    }

    Boolean logRecipients = (Boolean) this.settings.get(EvalSettings.LOG_EMAIL_RECIPIENTS);
    if (logRecipients == null) {
        logRecipients = false;
    }

    List<String> recipients = new ArrayList<>();

    Date availableEmailSent = null;
    if (availableEmailEnabled) {
        // do not send email to users who have gotten an available email recently (wait number of days specified by reminderFrequency) 
        availableEmailSent = new Date(
                System.currentTimeMillis() - (reminderFrequency.longValue() * MILLISECONDS_PER_DAY));
    }
    Date reminderEmailSent = new Date();

    int count = this.evaluationService.selectConsoliatedEmailRecipients(availableEmailEnabled,
            availableEmailSent, true, reminderEmailSent, EvalConstants.EMAIL_TEMPLATE_CONSOLIDATED_REMINDER);
    LOG.debug("Number of evalAssignUser entities selected for reminder emails: " + count);
    if (count > 0) {
        if (jobStatusReporter != null) {
            jobStatusReporter.reportProgress(jobId, "sendingReminders", Integer.toString(count));
            jobStatusReporter.reportProgress(jobId, "reminderGroups",
                    Integer.toString(this.evaluationService.countDistinctGroupsInConsolidatedEmailMapping()));
        }
        int page = 0;
        List<String> userIds;
        do {
            List<Map<String, Object>> userMap = this.evaluationService.getConsolidatedEmailMapping(false,
                    batchSize, page++);
            userIds = processConsolidatedEmails(jobId, userMap, jobStatusReporter);
            if (userIds != null)
                recipients.addAll(userIds);
            takeShortBreak(waitInterval);
        } while (userIds != null && !userIds.isEmpty());
    }
    this.evaluationService.resetConsolidatedEmailRecipients();

    if (jobId != null && jobStatusReporter != null) {
        jobStatusReporter.reportProgress(jobId, "reminders",
                calculateElapsedTimeMessage(new Date(), reminderEmailSent));
        jobStatusReporter.reportProgress(jobId, "reminderUsers", Integer.toString(recipients.size()));
    }
    return recipients.toArray(new String[] {});
}

From source file:com.redhat.rhn.frontend.xmlrpc.system.test.SystemHandlerTest.java

public void testScheduleScript() throws Exception {
    Server server = ServerFactoryTest.createTestServer(admin, true,
            ServerConstants.getServerGroupTypeProvisioningEntitled());
    SystemManagerTest.giveCapability(server.getId(), "script.run", new Long(1));

    List serverIds = new ArrayList();
    serverIds.add(server.getId().intValue());

    Integer actionId = handler.scheduleScriptRun(admin, serverIds, "root", "root", new Integer(600), "",
            new Date());

    ScriptRunAction newAction = (ScriptRunAction) ActionManager.lookupAction(admin,
            new Long(actionId.longValue()));
    assertNotNull(newAction);/*from   w w  w.ja va  2s.c om*/
    ScriptActionDetails newActionDetails = newAction.getScriptActionDetails();
    assertNotNull(newActionDetails);

    // Results not yet available:
    Object[] result = handler.getScriptResults(admin, actionId);
    assertEquals(0, result.length);
}

From source file:com.redhat.rhn.frontend.xmlrpc.system.test.SystemHandlerTest.java

public void testGetScriptResult() throws Exception {
    Calendar futureCal = GregorianCalendar.getInstance();
    futureCal.set(2050, 12, 14);/*from  w  ww  . java  2 s. c  om*/

    Server server = ServerFactoryTest.createTestServer(admin, true,
            ServerConstants.getServerGroupTypeProvisioningEntitled());
    SystemManagerTest.giveCapability(server.getId(), "script.run", new Long(1));

    List serverIds = new ArrayList();
    serverIds.add(server.getId().intValue());

    Integer actionId = handler.scheduleScriptRun(admin, serverIds, "root", "root", new Integer(600), "",
            new Date());

    ScriptRunAction newAction = (ScriptRunAction) ActionManager.lookupAction(admin,
            new Long(actionId.longValue()));

    ScriptActionDetails newActionDetails = newAction.getScriptActionDetails();
    newActionDetails.setParentAction(newAction);

    ScriptResult result = new ScriptResult();
    result.setServerId(server.getId());
    result.setReturnCode(new Long(1));
    result.setStartDate(new Date());
    result.setStopDate(futureCal.getTime());
    result.setParentScriptActionDetails(newActionDetails);
    result.setActionScriptId(newActionDetails.getId());

    newActionDetails.addResult(result);
    newAction.setScriptActionDetails(newActionDetails);

    ActionFactory.save(newAction);
    flushAndEvict(newAction);

    Object[] scriptResult = handler.getScriptResults(admin, new Integer(newAction.getId().intValue()));
    assertEquals(1, scriptResult.length);
}

From source file:org.jlibrary.core.jcr.modules.JCRResourcesModule.java

public ResourceNode createResource(Ticket ticket, ResourceNodeProperties properties)
        throws RepositoryException, SecurityException {

    try {/*from w  ww  . ja  v a  2s.  c  o  m*/
        String parentId = (String) properties.getProperty(ResourceNodeProperties.RESOURCE_PARENT_ID).getValue();
        String name = ((String) properties.getProperty(ResourceNodeProperties.RESOURCE_NAME).getValue());
        String path = ((String) properties.getProperty(ResourceNodeProperties.RESOURCE_PATH).getValue());
        String extension = FileUtils.getExtension(path);
        String description = ((String) properties.getProperty(ResourceNodeProperties.RESOURCE_DESCRIPTION)
                .getValue());
        Integer typecode = ((Integer) properties.getProperty(ResourceNodeProperties.RESOURCE_TYPECODE)
                .getValue());

        javax.jcr.Session session = SessionManager.getInstance().getSession(ticket);
        if (session == null) {
            throw new RepositoryException("Session has expired. Please log in again.");
        }
        javax.jcr.Node root = JCRUtils.getRootNode(session);
        javax.jcr.Node parent = session.getNodeByUUID(parentId);

        if (!JCRSecurityService.canWrite(parent, ticket.getUser().getId())) {
            throw new SecurityException(SecurityException.NOT_ENOUGH_PERMISSIONS);
        }

        javax.jcr.Node child = null;
        Object syncLock = LockUtility.obtainLock(parent);
        synchronized (syncLock) {

            String escapedName = JCRUtils.buildValidChildNodeName(parent, extension, name);
            child = parent.addNode(escapedName, JCRConstants.JCR_FILE);
            name = Text.unescape(escapedName);
            if ((extension != null) && !escapedName.endsWith(extension)) {
                escapedName += extension;
            }

            child.addMixin(JCRConstants.JCR_REFERENCEABLE);
            child.addMixin(JCRConstants.JCR_LOCKABLE);
            child.addMixin(JLibraryConstants.RESOURCE_MIXIN);

            child.setProperty(JLibraryConstants.JLIBRARY_NAME, name);
            child.setProperty(JLibraryConstants.JLIBRARY_DESCRIPTION, description);
            child.setProperty(JLibraryConstants.JLIBRARY_CREATED, Calendar.getInstance());
            child.setProperty(JLibraryConstants.JLIBRARY_IMPORTANCE, Node.IMPORTANCE_MEDIUM.longValue());
            child.setProperty(JLibraryConstants.JLIBRARY_CREATOR, ticket.getUser().getId());
            child.setProperty(JLibraryConstants.JLIBRARY_TYPECODE, typecode.longValue());
            child.setProperty(JLibraryConstants.JLIBRARY_POSITION, 0);

            child.setProperty(JLibraryConstants.JLIBRARY_PATH,
                    repositoryService.getPath(parent) + FileUtils.getFileName(path));

            javax.jcr.Node resNode = child.addNode(JCRConstants.JCR_CONTENT, JCRConstants.JCR_RESOURCE);
            resNode.addMixin(JLibraryConstants.CONTENT_MIXIN);

            byte[] content = (byte[]) properties.getProperty(ResourceNodeProperties.RESOURCE_CONTENT)
                    .getValue();
            if (content == null) {
                // Empty resource
                content = new byte[] {};
            }
            //TODO: Handle encoding 
            String mimeType = Types.getMimeTypeForExtension(FileUtils.getExtension(path));
            resNode.setProperty(JCRConstants.JCR_MIME_TYPE, mimeType);
            resNode.setProperty(JCRConstants.JCR_ENCODING, JCRConstants.DEFAULT_ENCODING);
            resNode.setProperty(JCRConstants.JCR_DATA, new ByteArrayInputStream(content));
            Calendar lastModified = Calendar.getInstance();
            lastModified.setTimeInMillis(new Date().getTime());
            resNode.setProperty(JCRConstants.JCR_LAST_MODIFIED, lastModified);

            child.setProperty(JLibraryConstants.JLIBRARY_SIZE, content.length);

            // Handle resource restrictions
            child.setProperty(JLibraryConstants.JLIBRARY_RESTRICTIONS, new Value[] {});
            javax.jcr.Node userNode = JCRSecurityService.getUserNode(session, ticket.getUser().getId());
            JCRRepositoryService.addRestrictionsToNode(child, parent, userNode);

            if (ticket.isAutocommit()) {
                session.save();
            }
        }
        return JCRAdapter.createResource(child, parentId, root.getUUID());
    } catch (Throwable e) {
        logger.error(e.getMessage(), e);
        throw new RepositoryException(e);
    }
}