Example usage for java.util Map.Entry get

List of usage examples for java.util Map.Entry get

Introduction

In this page you can find the example usage for java.util Map.Entry get.

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:org.silverpeas.core.notification.user.delayed.DelayedNotificationManagerIT.java

@Test
public void testSaveDelayedNotification() throws Exception {
    final NotifChannel[] channels = NotifChannel.values();
    final NotifAction[] actions = NotifAction.values();
    int userIdTest = 1000;
    Map<NotifChannel, List<DelayedNotificationData>> delayedNotificationDataMap;
    final NotificationResourceData notificationResourceData = buildNotificationResourceData(TEST_CASE_3);
    DelayedNotificationData newDelayedNotificationData;
    DelayedNotificationData delayedNotificationData;
    int count = 0;
    int count2 = 0;
    Date dateBeforeSave;//from  w ww  .j av a2  s . c om
    for (int i = 0; i < channels.length; i++) {
        userIdTest += i;
        dateBeforeSave = new Date();
        for (final NotifAction action : actions) {
            newDelayedNotificationData = new DelayedNotificationData();
            newDelayedNotificationData.setUserId(userIdTest);
            newDelayedNotificationData.setFromUserId(2 * userIdTest);
            newDelayedNotificationData.setChannel(channels[i]);
            newDelayedNotificationData.setAction(action);
            newDelayedNotificationData.setLanguage("fr");
            if ((count % 3) == 0) {
                newDelayedNotificationData.setResource(notificationResourceData);
            } else {
                newDelayedNotificationData.setResource(buildNotificationResourceData(TEST_CASE_3));
            }
            if ((count % 2) == 0) {
                newDelayedNotificationData.setMessage("message" + count);
            }
            if ((count % 4) == 0) {
                newDelayedNotificationData.setCreationDate(dateBeforeSave);
            }
            assertThat(newDelayedNotificationData.isValid(), is(true));
            manager.saveDelayedNotification(newDelayedNotificationData);
            manager.saveDelayedNotification(newDelayedNotificationData);
            if ((count % 4) == 0) {
                final String idTest = newDelayedNotificationData.getId();
                if (count == 0) {
                    newDelayedNotificationData.setId((Long) null);
                }
                newDelayedNotificationData.getResource().setId((Long) null);
                manager.saveDelayedNotification(newDelayedNotificationData);
                assertThat(idTest, is(newDelayedNotificationData.getId()));
            }
            count++;
        }

        delayedNotificationDataMap = manager.findDelayedNotificationByUserIdGroupByChannel(userIdTest,
                getAimedChannelsAll());
        assertThat(delayedNotificationDataMap, notNullValue());
        assertThat(delayedNotificationDataMap.size(), is(1));
        for (final Map.Entry<NotifChannel, List<DelayedNotificationData>> mapEntry : delayedNotificationDataMap
                .entrySet()) {
            assertThat(mapEntry.getValue().size(), is(actions.length));
            for (int j = 0; j < actions.length; j++) {
                delayedNotificationData = mapEntry.getValue().get(j);
                assertThat(delayedNotificationData.getId(), is(String.valueOf(1001l + count2)));
                assertThat(delayedNotificationData.getUserId(), is(userIdTest));
                assertThat(delayedNotificationData.getFromUserId(), is(2 * userIdTest));
                assertThat(delayedNotificationData.getChannel(), is(channels[i]));
                assertThat(delayedNotificationData.getAction(), is(actions[j]));
                assertThat(delayedNotificationData.getResource().getId(), is("10"));
                assertThat(delayedNotificationData.getCreationDate(), notNullValue());
                assertThat(delayedNotificationData.getCreationDate(), greaterThanOrEqualTo(dateBeforeSave));
                if ((count2 % 2) == 0) {
                    assertThat(delayedNotificationData.getMessage(), is("message" + count2));
                } else {
                    assertThat(delayedNotificationData.getMessage(), nullValue());
                }
                count2++;
            }
        }
    }
}

From source file:org.kuali.rice.kew.actions.RecallActionTest.java

@Test
public void testRecallDoesNotRecallDocumentWhenProcessed() throws Exception {
    WorkflowDocument document = WorkflowDocumentFactory.createDocument(EWESTFAL, RECALL_TEST_DOC);
    document.route("");

    for (String user : new String[] { JHOPF, EWESTFAL, RKIRKEND, NATJOHNS, BMCGOUGH }) {
        document = WorkflowDocumentFactory.loadDocument(user, document.getDocumentId());
        document.approve("");
    }//from  ww  w .  j  a  va 2 s  .  c  o  m

    document.refresh();
    assertTrue("Document should be processed", document.isProcessed());
    assertTrue("Document should be approved", document.isApproved());
    assertFalse("Document should not be final", document.isFinal());

    document = WorkflowDocumentFactory.loadDocument(EWESTFAL, document.getDocumentId());
    document.recall("recalling when processed should not recall the document", true);

    Map<String, List<ErrorMessage>> errorMessages = GlobalVariables.getMessageMap().getErrorMessages();
    assertTrue(errorMessages.size() == 1);
    for (Map.Entry<String, List<ErrorMessage>> errorMessage : errorMessages.entrySet()) {
        assertTrue(errorMessage.getValue().get(0).getErrorKey()
                .equals(RiceKeyConstants.MESSAGE_RECALL_NOT_SUPPORTED));
    }

    // Verify the document status is still PROCESSED
    assertTrue("Document should be processed", document.isProcessed());
    assertTrue("Document should be approved", document.isApproved());
    assertFalse("Document should not be final", document.isFinal());

    GlobalVariables.getMessageMap().clearErrorMessages();
}

From source file:org.alfresco.repo.activities.post.lookup.PostLookup.java

private List<ActivityPostEntity> rollupPosts(List<ActivityPostEntity> activityPosts) throws SQLException {
    Map<UserRollupActivity, List<ActivityPostEntity>> rollupPosts = new HashMap<UserRollupActivity, List<ActivityPostEntity>>();

    List<ActivityPostEntity> result = new ArrayList<ActivityPostEntity>(activityPosts.size());

    for (final ActivityPostEntity post : activityPosts) {
        if (rollupTypes.containsKey(post.getActivityType()) && (post.getParentNodeRef() != null)) {
            UserRollupActivity key = new UserRollupActivity(post.getUserId(), post.getActivityType(),
                    post.getParentNodeRef());
            List<ActivityPostEntity> posts = rollupPosts.get(key);
            if (posts == null) {
                posts = new ArrayList<ActivityPostEntity>();
                rollupPosts.put(key, posts);
            }//  w  ww. j  a  va  2 s  . c  o m
            posts.add(post);
        } else {
            result.add(post);
        }
    }

    for (final Map.Entry<UserRollupActivity, List<ActivityPostEntity>> entry : rollupPosts.entrySet()) {
        final int count = entry.getValue().size();
        if (count >= rollupCount) {
            final ActivityPostEntity oldPost = entry.getValue().get(0);
            final String tenantDomain = oldPost.getTenantDomain();

            TenantUtil.runAsSystemTenant(new TenantUtil.TenantRunAsWork<Void>() {
                public Void doWork() throws Exception {
                    String postUserId = oldPost.getUserId();

                    // rollup - create a new 'posted' event that represents the rolled-up activity (and set others to 'processed')
                    ActivityPostEntity newPost = new ActivityPostEntity();

                    newPost.setActivityType(rollupTypes.get(oldPost.getActivityType()));
                    newPost.setPostDate(oldPost.getPostDate());
                    newPost.setUserId(postUserId);
                    newPost.setSiteNetwork(oldPost.getSiteNetwork());
                    newPost.setAppTool(oldPost.getAppTool());
                    newPost.setLastModified(oldPost.getLastModified());
                    newPost.setTenantDomain(tenantDomain);
                    newPost.setJobTaskNode(1);

                    try {
                        JSONObject jo = new JSONObject();
                        jo.put(JSON_NODEREF_PARENT, oldPost.getParentNodeRef().toString());
                        jo.put(JSON_TENANT_DOMAIN, tenantDomain);
                        jo.put(JSON_TITLE, "" + count);

                        Pair<String, String> firstLastName = lookupPerson(postUserId);
                        if (firstLastName != null) {
                            jo.put(JSON_FIRSTNAME, firstLastName.getFirst());
                            jo.put(JSON_LASTNAME, firstLastName.getSecond());
                        }

                        Path path = lookupPath(oldPost.getParentNodeRef());
                        if (path != null) {
                            String displayPath = PathUtil.getDisplayPath(path, true);
                            if (displayPath != null) {
                                // note: PathUtil.getDisplayPath returns prefix path as: '/company_home/sites/' rather than /Company Home/Sites'
                                String prefix = "/company_home/sites/"
                                        + tenantService.getBaseName(oldPost.getSiteNetwork())
                                        + "/documentLibrary";
                                int idx = displayPath.indexOf(prefix);
                                if (idx == 0) {
                                    displayPath = displayPath.substring(prefix.length());
                                }

                                // Share-specific
                                jo.put(JSON_PAGE, "documentlibrary?path=" + displayPath);
                            }
                        }

                        newPost.setActivityData(jo.toString());
                        newPost.setStatus(ActivityPostEntity.STATUS.POSTED.toString());
                    } catch (JSONException e) {
                        logger.warn("Unable to create activity data: " + e);
                        newPost.setStatus(ActivityPostEntity.STATUS.ERROR.toString());
                    }

                    for (ActivityPostEntity post : entry.getValue()) {
                        post.setStatus(ActivityPostEntity.STATUS.PROCESSED.toString());
                    }

                    // add the new POSTED
                    entry.getValue().add(newPost);

                    return null;
                }
            }, tenantDomain);
        }

        result.addAll(entry.getValue());
    }

    return result;
}

From source file:org.nuxeo.ecm.social.workspace.listeners.SocialWorkspaceMembersManagementListener.java

private void notifyForDocument(Map.Entry<DocumentRef, List<Event>> eventContexts) {
    List<Principal> addedMembers = new ArrayList<Principal>();
    List<Principal> removedMembers = new ArrayList<Principal>();

    for (Event event : eventContexts.getValue()) {
        DocumentEventContext docCtx = (DocumentEventContext) event.getContext();
        List<Principal> principals = (List<Principal>) docCtx.getProperty(CTX_PRINCIPALS_PROPERTY);
        if (event.getName().equals(EVENT_MEMBERS_ADDED)) {
            addedMembers.addAll(principals);
        } else if (event.getName().equals(EVENT_MEMBERS_REMOVED)) {
            removedMembers.addAll(principals);
        }/*from  w  w w.ja v  a2  s .c o m*/
    }

    if (!addedMembers.isEmpty() || !removedMembers.isEmpty()) {
        DocumentEventContext context = (DocumentEventContext) eventContexts.getValue().get(0).getContext();
        notifyMembers(context, addedMembers, removedMembers);
    }
}

From source file:eu.smartenit.sdn.floodlight090.dtm.DTM.java

private synchronized void calculateRInvMap(RVector referenceVector) {
    long R[] = new long[2];
    int dcNumber = 0;

    for (Map.Entry<Short, Long> rVectorMap : daRouterRVectorMap.entrySet()) {
        if (rVectorMap.getValue() == referenceVector.getVectorValues().get(0).getValue()) {
            R[0] = rVectorMap.getValue();
        } else if (rVectorMap.getValue() == referenceVector.getVectorValues().get(1).getValue()) {
            R[1] = rVectorMap.getValue();
        }/*  ww w  . j  a v a2 s .c  o  m*/

        for (Map.Entry<Integer, ArrayList<Short>> entrySet : dcNumberOfPortsMap.entrySet()) {
            if (rVectorMap.getKey() == entrySet.getValue().get(0)) {
                dcNumber = entrySet.getKey();
            }
        }
    }

    ArrayList<Double> rInv = new ArrayList<>();
    rInv.add((double) (R[1] / (R[0] + R[1])));
    rInv.add((double) (R[0] / (R[0] + R[1])));

    dcNumberInvRMap.put(dcNumber, rInv);

}

From source file:org.apache.camel.component.cxf.jaxrs.DefaultCxfRsBinding.java

/**
 * We will return an empty Map unless the response parameter is a {@link Response} object. 
 *///from w  w w .j  ava 2 s. c o  m
public Map<String, Object> bindResponseHeadersToCamelHeaders(Object response, Exchange camelExchange)
        throws Exception {

    Map<String, Object> answer = new HashMap<String, Object>();
    if (response instanceof Response) {

        for (Map.Entry<String, List<Object>> entry : ((Response) response).getMetadata().entrySet()) {
            if (!headerFilterStrategy.applyFilterToExternalHeaders(entry.getKey(), entry.getValue(),
                    camelExchange)) {

                String mappedHeaderName = cxfToCamelHeaderMap.get(entry.getKey());
                if (mappedHeaderName == null) {
                    mappedHeaderName = entry.getKey();
                }

                if (LOG.isTraceEnabled()) {
                    LOG.trace("Populate external header " + entry.getKey() + "=" + entry.getValue() + " as "
                            + mappedHeaderName);
                }

                answer.put(mappedHeaderName, entry.getValue().get(0));

            } else {
                if (LOG.isTraceEnabled()) {
                    LOG.trace("Drop external header " + entry.getKey() + "=" + entry.getValue());
                }
            }
        }

        // put response code in Camel message header
        answer.put(Exchange.HTTP_RESPONSE_CODE, ((Response) response).getStatus());
    }

    return answer;
}

From source file:org.kuali.rice.kew.actions.RecallActionTest.java

@Test
public void testRecallDoesNotRecallDocumentWhenFinal() throws Exception {
    WorkflowDocument document = WorkflowDocumentFactory.createDocument(EWESTFAL, RECALL_TEST_DOC);
    document.route("");

    for (String user : new String[] { JHOPF, EWESTFAL, RKIRKEND, NATJOHNS, BMCGOUGH }) {
        document = WorkflowDocumentFactory.loadDocument(user, document.getDocumentId());
        document.approve("");
    }//w  w  w. j  av  a 2s.c om
    document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("xqi"), document.getDocumentId());
    document.acknowledge("");

    document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jthomas"), document.getDocumentId());
    document.fyi();

    for (ActionRequest a : document.getRootActionRequests()) {
        System.err.println(a);
        if (a.isAcknowledgeRequest() || a.isFyiRequest()) {
            System.err.println(a.getPrincipalId());
            System.err.println(KimApiServiceLocator.getIdentityService().getPrincipal(a.getPrincipalId())
                    .getPrincipalName());
        }
    }

    assertFalse("Document should not be processed", document.isProcessed());
    assertTrue("Document should be approved", document.isApproved());
    assertTrue("Document should be final", document.isFinal());

    document = WorkflowDocumentFactory.loadDocument(EWESTFAL, document.getDocumentId());
    document.recall("recalling when final should not recall the document", true);

    Map<String, List<ErrorMessage>> errorMessages = GlobalVariables.getMessageMap().getErrorMessages();
    assertTrue(errorMessages.size() == 1);
    for (Map.Entry<String, List<ErrorMessage>> errorMessage : errorMessages.entrySet()) {
        assertTrue(errorMessage.getValue().get(0).getErrorKey()
                .equals(RiceKeyConstants.MESSAGE_RECALL_NOT_SUPPORTED));
    }

    // Verify the document status is still FINAL
    assertFalse("Document should not be processed", document.isProcessed());
    assertTrue("Document should be approved", document.isApproved());
    assertTrue("Document should be final", document.isFinal());

    GlobalVariables.getMessageMap().clearErrorMessages();
}

From source file:org.openmrs.util.databasechange.ConceptValidatorChangeSet.java

/**
 * Sets the fully specified name from available names
 *
 * @param localeConceptNamesMap, list of all concept names for the concept
 * @return/*from  ww  w .j  a v  a  2  s  .co m*/
 */
private boolean setFullySpecifiedName(int conceptId, Map<Locale, List<ConceptName>> localeConceptNamesMap) {

    //Pick the first name in any locale by searching in order from the allowed locales
    for (Locale allowedLoc : allowedLocales) {
        List<ConceptName> possibleFullySpecNames = localeConceptNamesMap.get(allowedLoc);
        if (CollectionUtils.isEmpty(possibleFullySpecNames)) {
            continue;
        }

        //try the synonyms
        for (ConceptName cn : possibleFullySpecNames) {
            if (cn.isSynonym()) {
                cn.setConceptNameType(ConceptNameType.FULLY_SPECIFIED);
                reportUpdatedName(cn, "ConceptName with id " + cn.getConceptNameId() + " (" + cn.getName()
                        + ") in locale '" + allowedLoc.getDisplayName()
                        + "' has been set as the fully specified name for concept with id : " + conceptId);
                return true;
            }
        }

        //try the short names
        for (ConceptName cn : possibleFullySpecNames) {
            if (cn.isShort()) {
                cn.setConceptNameType(ConceptNameType.FULLY_SPECIFIED);
                reportUpdatedName(cn,
                        "ConceptName with id " + cn.getConceptNameId() + " (" + cn.getName() + ") in locale '"
                                + allowedLoc.getDisplayName()
                                + "' has been changed from short to fully specified name for concept with id : "
                                + conceptId);
                return true;
            }
        }
    }

    //pick a name randomly from the conceptName map
    for (Map.Entry<Locale, List<ConceptName>> entry : localeConceptNamesMap.entrySet()) {
        Locale locale = entry.getKey();
        if (locale != null) {
            ConceptName fullySpecName = entry.getValue().get(0);
            fullySpecName.setConceptNameType(ConceptNameType.FULLY_SPECIFIED);
            reportUpdatedName(fullySpecName,
                    "ConceptName with id " + fullySpecName.getConceptNameId() + " (" + fullySpecName.getName()
                            + ") in locale '" + locale.getDisplayName()
                            + "' has been set as the fully specified name for concept with id : " + conceptId);
            return true;
        }
    }

    //most probably this concept has no names added to it yet
    return false;
}

From source file:org.wso2.carbon.is.migration.service.v530.migrator.ClaimDataMigrator.java

private void mapAttributesAgainstTenant(StringBuilder report,
        Map<String, Map<String, List<String>>> tenantDialectMappedAttributes) {

    Map<String, Set<String>> claimsToAddMap = new HashMap<>();
    if (tenantDialectMappedAttributes != null) {
        for (Map.Entry<String, Map<String, List<String>>> entry : tenantDialectMappedAttributes.entrySet()) {
            String tenantDomain = entry.getKey();
            Set<String> claimsToAdd = new HashSet<>();
            if (claimsToAddMap.get(tenantDomain) != null) {
                claimsToAdd = claimsToAddMap.get(tenantDomain);
            }/*from  w  w  w  .  j  a v a 2s. c  o  m*/

            if (entry.getValue() != null) {
                List<String> localAttributes = entry.getValue().get(ClaimConstants.LOCAL_CLAIM_DIALECT_URI);
                for (Map.Entry<String, List<String>> dialect : entry.getValue().entrySet()) {
                    if (!ClaimConstants.LOCAL_CLAIM_DIALECT_URI.equalsIgnoreCase(dialect.getKey())) {
                        List<String> remoteClaimAttributes = dialect.getValue();
                        if (remoteClaimAttributes != null) {
                            for (String remoteClaimAttribute : remoteClaimAttributes) {
                                if (!localAttributes.contains(remoteClaimAttribute)) {
                                    claimsToAdd.add(remoteClaimAttribute);
                                    isSuccess = false;
                                    report.append("\n\n" + count + ")  Mapped Attribute : "
                                            + remoteClaimAttribute + " in dialect :" + dialect.getKey()
                                            + " is not associated to any of the local claim in "
                                            + "tenant domain: " + tenantDomain);

                                    if (log.isDebugEnabled()) {
                                        log.debug("Mapped Attribute : " + remoteClaimAttribute + " in dialect :"
                                                + dialect.getKey()
                                                + " is not associated to any of the local claim in"
                                                + " tenant domain: " + tenantDomain);
                                    }
                                    count++;
                                }
                            }
                        }
                    }
                }
            }
            claimsToAddMap.put(tenantDomain, claimsToAdd);
        }
    }
}

From source file:org.apache.hadoop.hbase.master.TestRegionPlacement.java

/**
 * Shuffle the assignment plan by switching two favored node positions.
 * @param plan The assignment plan/*from   w w w  .jav  a 2s. c  o m*/
 * @param p1 The first switch position
 * @param p2 The second switch position
 * @return
 */
private FavoredNodesPlan shuffleAssignmentPlan(FavoredNodesPlan plan, FavoredNodesPlan.Position p1,
        FavoredNodesPlan.Position p2) {
    FavoredNodesPlan shuffledPlan = new FavoredNodesPlan();

    for (Map.Entry<HRegionInfo, List<ServerName>> entry : plan.getAssignmentMap().entrySet()) {
        HRegionInfo region = entry.getKey();

        // copy the server list from the original plan
        List<ServerName> shuffledServerList = new ArrayList<ServerName>();
        shuffledServerList.addAll(entry.getValue());

        // start to shuffle
        shuffledServerList.set(p1.ordinal(), entry.getValue().get(p2.ordinal()));
        shuffledServerList.set(p2.ordinal(), entry.getValue().get(p1.ordinal()));

        // update the plan
        shuffledPlan.updateAssignmentPlan(region, shuffledServerList);
    }
    return shuffledPlan;
}