public ListWrapper<T> expand(ExpandContext<ListWrapper<T>> context, EntityExpanderResolver expanderResolver, EntityCrawler entityCrawler) { final ListWrapper<T> entity = context.getEntity(); final Set<Field> collectionFields = Sets.newHashSet(); for (Class cls = entity.getClass(); cls != null; cls = cls.getSuperclass()) { final Field[] fields = cls.getDeclaredFields(); for (Field field : fields) { if (Collection.class.isAssignableFrom(field.getType())) { collectionFields.add(field); } } } if (collectionFields.isEmpty()) { throw new RuntimeException("Entity " + entity.getClass() + " has no collection field, cannot expand."); } if (collectionFields.size() > 1) { throw new RuntimeException("Entity " + entity.getClass() + " has more than one collection field, cannot determine which collection to expand."); } setFieldValue(collectionFields.iterator().next(), entity, entity.getCallback().getItems(context.getEntityExpandParameter().getIndexes(context.getExpandable()))); entityCrawler.crawl(entity, context.getEntityExpandParameter().getExpandParameter(context.getExpandable()), expanderResolver); return entity; }
public Object expand(ExpandContext<Object> context, EntityExpanderResolver expanderResolver, EntityCrawler entityCrawler) { final Object entity = context.getEntity(); try { method.invoke(entity, context.getEntityExpandParameter().getIndexes(context.getExpandable())); } catch (IllegalAccessException e) { throw new ExpandException(e); } catch (InvocationTargetException e) { throw new ExpandException(e); } entityCrawler.crawl(entity, context.getEntityExpandParameter().getExpandParameter(context.getExpandable()), expanderResolver); return entity; } }
public final T expand(ExpandContext<T> context, EntityExpanderResolver expanderResolver, EntityCrawler entityCrawler) { final T expandedEntity = expandInternal(context.getEntity()); if (!context.getEntityExpandParameter().isEmpty()) { entityCrawler.crawl(expandedEntity, context.getEntityExpandParameter().getExpandParameter(context.getExpandable()), expanderResolver); } return expandedEntity; }
public void intercept(MethodInvocation invocation) throws IllegalAccessException, InvocationTargetException { invocation.invoke(); HttpRequestContext request = invocation.getHttpContext().getRequest(); HttpResponseContext response = invocation.getHttpContext().getResponse(); final ExpandParameter expandParameter = new DefaultExpandParameter(request.getQueryParameters().get(expandParameterName)); new EntityCrawler(additionalExpandsProviders).crawl(response.getEntity(), expandParameter, expanderResolver); } }
public IssueBean apply(@Nullable Issue issue) { IssueBean bean = issueBeanBuilder.build(issue); // explicitly crawl all over this motha, since atlassian-rest didn't take care of business. entityCrawler.crawl(bean, expand, expandResolver); return bean; } }
public Option<String> marshallBeanToJson(Object object, Collection<String> expands) { checkNotNull(object); // expand stuff... if (!expands.isEmpty()) { new EntityCrawler().crawl(object, new DefaultExpandParameter(expands), getExpanders()); } JaxbJsonMarshaller m = DefaultJaxbJsonMarshaller.builder().modules(getModules()).build(); try { return option(m.marshal(object)); } catch (JsonMarshallingException e) { log.error(String.format("Unable to Atlassian marshall the object of class %s", object.getClass()), e); return none(); } }
private static String marshallBean(Object object, Collection<String> expand, List<Module> modules) throws JAXBException, IOException { // expand stuff... if (!expand.isEmpty()) { new EntityCrawler().crawl(object, new DefaultExpandParameter(expand), getExpanders()); } JaxbJsonMarshaller m = DefaultJaxbJsonMarshaller.builder().modules(modules).build(); final String result = m.marshal(object); LOG.log(Level.FINE, "Got marshalled output:\n" + result); return result; }
private ProjectBean createAndExpandProjectBean(Project project, ProjectBeanBuilder builder, String expand) { StringList expandList = StringList.fromQueryParam(expand); List<String> expandItems = (expandList == null ? ImmutableList.<String>of() : expandList.asList()); //Could be expensive call so only do when needed (vs SelfExpandingExpander / bean doing its own expansion) if (expandItems.contains(EXPAND_PROJECT_KEYS) || expandItems.contains(EXPAND_WILDCARD)) { builder.projectKeys(projectManager.getAllProjectKeys(project.getId())); } ProjectBean projectBean = builder.build(); EntityExpanderResolver expandResolver = new SelfExpandingExpander.Resolver(); EntityCrawler entityCrawler = new EntityCrawler(); ExpandParameter expandParameter = new DefaultExpandParameter(expandItems); entityCrawler.crawl(projectBean, expandParameter, expandResolver); return projectBean; }
@Override public FilterBean apply(SearchRequest filter) { final ApplicationUser user = authenticationContext.getUser(); final String canonicalBaseUrl = velocityRequestContextFactory.getJiraVelocityRequestContext().getCanonicalBaseUrl(); boolean isFavourite = this.isFavourite == null ? user != null && favouritesService.isFavourite(user, filter) : this.isFavourite; final FilterBean bean = beanBuilderFactory.newFilterBeanBuilder() .filter(filter) .context(uriInfo, canonicalBaseUrl) .owner(filter.getOwner()) .favourite(isFavourite).build(); entityCrawler.crawl(bean, expand, expandResolver); return bean; } }