private Map<String, Map<Integer, Object>> createVersionedRepresentations(final Map<String, FieldData> fields, final Issue issue) { return ImmutableMaps.transformValue(fields, new Function<FieldData, Map<Integer, Object>>() { @Override public Map<Integer, Object> apply(final FieldData fieldData) { // The HashMap is used here because we need to store null values. final Map<Integer, Object> representations = new HashMap<Integer, Object>(); representations.put(FIRST_REPRESENTATION_VERSION, fieldData.getJsonData().getData()); if (!(fieldData.field instanceof CustomField)) { return representations; } final CustomField field = (CustomField) fieldData.field; final CustomFieldType customFieldType = field.getCustomFieldType(); if (!(customFieldType instanceof AbstractCustomFieldType)) { return representations; } final AbstractCustomFieldType abstractCustomFieldType = (AbstractCustomFieldType) customFieldType; final CustomFieldTypeModuleDescriptor descriptor = abstractCustomFieldType.getDescriptor(); representations.putAll(createVersionedRepresentationsForField(field, descriptor, issue)); return representations; } }); }
private Map<Integer, Object> createVersionedRepresentationsForField(final CustomField field, final CustomFieldTypeModuleDescriptor descriptor, final Issue issue) { return ImmutableMaps.collect(descriptor.getRestSerializers(), new Function<Map.Entry<Integer, CustomFieldRestSerializer>, Option<Map.Entry<Integer, Object>>>() { @Override public Option<Map.Entry<Integer, Object>> apply(final Map.Entry<Integer, CustomFieldRestSerializer> entry) { return getSafelyVersionedRepresentation(entry.getValue(), entry.getKey(), field, issue).map(new Function<JsonData, Map.Entry<Integer, Object>>() { @Override public Map.Entry<Integer, Object> apply(final JsonData jsonData) { return Maps.immutableEntry(entry.getKey(), jsonData.getData()); } }); } }); }
private Map<Integer, String> readRestSerializerClassNames(final Element element) { @SuppressWarnings ("unchecked") final List<Element> restSerializerElements = element.elements(REST_SERIALIZER_ELEMENT_NAME); final Iterable<Map.Entry<Integer, String>> entries = Iterables.transform(restSerializerElements, new Function<Element, Map.Entry<Integer, String>>() { @Override public Map.Entry<Integer, String> apply(@Nullable final Element element) { final Integer version = parseVersionNumber(getRequiredAttributeValue(element, VERSION_NUMBER_ARGUMENT_NAME)); final String className = getRequiredAttributeValue(element, SERIALIZER_CLASS_ARGUMENT_NAME); return Maps.immutableEntry(version, className); } }); // ImmutableMaps.toMap already checks that all keys are individual. try { return ImmutableMaps.toMap(entries); } catch (IllegalArgumentException e) { throw new PluginParseException(REST_SERIALIZER_ELEMENT_NAME + "'s " + VERSION_NUMBER_ARGUMENT_NAME + " can't be duplicated", e); } }
/** * <p>Produces a relation between {@link com.atlassian.jira.application.ApplicationRole}s and {@link com.atlassian.jira.user.ApplicationUser}s * indicating which users will gain access to which applications if they will be added to given groups.</p> * <p>This method is useful only in seating counting. There is one gotcha: if users are already (or eventually will be) added to some * application, and we want to give them CORE access it's dry-run. We won't count them as jira-core users as it will be implied.</p> * @param users users to be checked * @param groupsToBeAdded groups to be added * @return users grouped by applications in which number of occupied seats should be incremented */ public Map<ApplicationRole, Set<ApplicationUser>> rolesToBeAddedForSeatingCountPurpose(Set<ApplicationUser> users, Set<String> groupsToBeAdded) { final SetMultimap<ApplicationUser, ApplicationRole> userToRoles = HashMultimap.create(); for (ApplicationUser user : users) { userToRoles.putAll(user, calculateRolesToBeAdded(user, groupsToBeAdded)); } return ImmutableMaps.transformValue( Multimaps.invertFrom(userToRoles, HashMultimap.create()).asMap(), ImmutableSet::copyOf ); }
private ImmutableMap<String, String> getDashboardItemProperties(final Long id) { List<String> propertyKeys = jsonEntityPropertyManager.findKeys(DASHBOARD_ITEM_PROPERTY.getDbEntityName(), id); return ImmutableMaps.toMap(Iterables.collect(propertyKeys, new Function<String, Option<Map.Entry<String, String>>>() { @Override public Option<Map.Entry<String, String>> apply(final String propertyKey) { return Option.option(jsonEntityPropertyManager.get(DASHBOARD_ITEM_PROPERTY.getDbEntityName(), id, propertyKey)).map(new Function<EntityProperty, Map.Entry<String, String>>() { @Override public Map.Entry<String, String> apply(final EntityProperty entityProperty) { final String value = fromJsonString(entityProperty.getValue()); return Maps.immutableEntry(propertyKey, Strings.nullToEmpty(value)); } }); } })); }