public static Object save(Repositories repositories, Object domainObj) throws HttpRequestMethodNotSupportedException { RepositoryInformation ri = findRepositoryInformation(repositories, domainObj.getClass()); if (ri == null) { throw new ResourceNotFoundException(); } Class<?> domainObjClazz = ri.getDomainType(); if (domainObjClazz != null) { Method saveMethod = ri.getCrudMethods().getSaveMethod(); if (saveMethod == null) { throw new HttpRequestMethodNotSupportedException("save"); } domainObj = ReflectionUtils.invokeMethod(saveMethod, repositories.getRepositoryFor(domainObjClazz), domainObj); } return domainObj; }
public static Repositories setUpRepositoryProviderMock(Map<Class<?>, Repository<?, ?>> repositoriesMap) { Repositories mockRepositories = Mockito.mock(Repositories.class); when(mockRepositories.getRepositoryFor(any())).thenAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Class<?> entityClass = (Class<?>) invocation.getArguments()[0]; Repository<?, ?> repository = repositoriesMap.get(entityClass); if (repository == null) { throw new IllegalArgumentException("Unsupported class: " + entityClass.getName()); } return repository; } }); RepositoryProvider.setRepositories(mockRepositories); return mockRepositories; }
@SuppressWarnings(value = "unchecked") public CrudRepository<Object, Serializable> find(@NotNull Class<?> domainClass) { Repositories repositories = new Repositories(listableBeanFactory); Iterator<Class<?>> it = repositories.iterator(); while (it.hasNext()) { Object repository = repositories.getRepositoryFor(domainClass); if (repository != null && repository instanceof CrudRepository) { return (CrudRepository<Object, Serializable>)repository; } } return null; }
@Test public void repositoriesAreAssignedToAppropriateStores() { Repositories repositories = new Repositories(context); assertThat(repositories.getEntityInformationFor(Customer.class), is(instanceOf(JpaEntityInformation.class))); assertThat(repositories.getEntityInformationFor(Order.class), is(instanceOf(MongoEntityInformation.class))); }
@Override public void setApplicationContext(ApplicationContext context) throws BeansException { Class<?>[] classes = GenericTypeResolver.resolveTypeArguments(this.getClass(), RepoBasedConverter.class); Class<?> clazz = classes[0]; this.repositories = new Repositories(context); this.entityInformation = (JpaEntityInformation<S, ID>) repositories.getEntityInformationFor(clazz); this.genericJpaRepository = (GenericJpaRepository<S, ID>) repositories.getRepositoryFor(clazz); this.useCache = genericJpaRepository instanceof CachingJpaRepository; }
@Autowired public ContentSearchRestController(Repositories repositories, ContentStoreService stores, PagedResourcesAssembler<Object> assembler) { super(assembler); this.repositories = repositories; this.stores = stores; this.reflectionService = new ReflectionServiceImpl(); }
@Autowired(required=false) public ContentPropertyCollectionRestController(ApplicationContext context, ContentStoreService stores, StoreByteRangeHttpRequestHandler handler) { super(); try { this.repositories = context.getBean(Repositories.class); } catch (BeansException be) { this.repositories = new Repositories(context); } this.storeService = stores; this.handler = handler; }
@Autowired public ContentEntityRestController(ApplicationContext context, ContentStoreService storeService, StoreByteRangeHttpRequestHandler handler) { try { this.repositories = context.getBean(Repositories.class); } catch (BeansException be) { this.repositories = new Repositories(context); } this.storeService = storeService; this.handler = handler; }
public static Object findOne(Repositories repositories, String repository, String id) throws HttpRequestMethodNotSupportedException { Object domainObj = null; RepositoryInformation ri = findRepositoryInformation(repositories, repository); if (ri == null) { throw new ResourceNotFoundException(); } Class<?> domainObjClazz = ri.getDomainType(); Class<?> idClazz = ri.getIdType(); Method findOneMethod = ri.getCrudMethods().getFindOneMethod(); if (findOneMethod == null) { throw new HttpRequestMethodNotSupportedException("fineOne"); } Object oid = new DefaultConversionService().convert(id, idClazz); domainObj = ReflectionUtils.invokeMethod(findOneMethod, repositories.getRepositoryFor(domainObjClazz), oid); if (null == domainObj) { throw new ResourceNotFoundException(); } return domainObj; }
public static Object findOne(Repositories repositories, Class<?> domainObjClass, String id) throws HttpRequestMethodNotSupportedException { Object domainObj = null; RepositoryInformation ri = findRepositoryInformation(repositories, domainObjClass); if (ri == null) { throw new ResourceNotFoundException(); } Class<?> domainObjClazz = ri.getDomainType(); Class<?> idClazz = ri.getIdType(); Method findOneMethod = ri.getCrudMethods().getFindOneMethod(); if (findOneMethod == null) { throw new HttpRequestMethodNotSupportedException("fineOne"); } Object oid = new DefaultConversionService().convert(id, idClazz); domainObj = ReflectionUtils.invokeMethod(findOneMethod, repositories.getRepositoryFor(domainObjClazz), oid); if (null == domainObj) { throw new ResourceNotFoundException(); } return domainObj; }
public static Iterable findAll(Repositories repositories, String repository) throws HttpRequestMethodNotSupportedException { Iterable entities = null; RepositoryInformation ri = findRepositoryInformation(repositories, repository); if (ri == null) { throw new ResourceNotFoundException(); } Class<?> domainObjClazz = ri.getDomainType(); Class<?> idClazz = ri.getIdType(); Method findAllMethod = ri.getCrudMethods().getFindAllMethod(); if (findAllMethod == null) { throw new HttpRequestMethodNotSupportedException("fineAll"); } entities = (Iterable)ReflectionUtils.invokeMethod(findAllMethod, repositories.getRepositoryFor(domainObjClazz)); if (null == entities) { throw new ResourceNotFoundException(); } return entities; }
public static RepositoryInformation findRepositoryInformation(Repositories repositories, String repository) { RepositoryInformation ri = null; for (Class<?> clazz : repositories) { RepositoryInformation candidate = repositories.getRepositoryInformationFor(clazz); if (candidate == null) { continue; } if (repository.equals(RepositoryUtils.repositoryPath(candidate))) { ri = repositories.getRepositoryInformationFor(clazz); break; } } return ri; }
public static RepositoryInformation findRepositoryInformation(Repositories repositories, Class<?> domainObjectClass) { RepositoryInformation ri = null; for (Class<?> clazz : repositories) { if (clazz.equals(domainObjectClass)) { return repositories.getRepositoryInformationFor(clazz); } } return ri; }
@Autowired(required=false) public ContentPropertyRestController(ApplicationContext context, ContentStoreService storeService, StoreByteRangeHttpRequestHandler handler) { super(); try { this.repositories = context.getBean(Repositories.class); } catch (BeansException be) { this.repositories = new Repositories(context); } this.storeService = storeService; this.handler = handler; }
private void replaceContentInternal(Repositories repositories, ContentStoreService stores, String repository, String id, String contentProperty, String contentId, String mimeType, InputStream stream) throws HttpRequestMethodNotSupportedException { Object domainObj = findOne(repositories, repository, id); PersistentProperty<?> property = this.getContentPropertyDefinition(repositories.getPersistentEntity(domainObj.getClass()), contentProperty); Object contentPropertyValue = this.getContentProperty(domainObj, property, contentId); if (BeanUtils.hasFieldWithAnnotation(contentPropertyValue, MimeType.class)) { BeanUtils.setFieldWithAnnotation(contentPropertyValue, MimeType.class, mimeType); } Class<?> contentEntityClass = ContentPropertyUtils.getContentPropertyType(property); ContentStoreInfo info = ContentStoreUtils.findContentStore(storeService, contentEntityClass); info.getImpementation().setContent(contentPropertyValue, stream); save(repositories, domainObj); }
@Autowired public ApplicationStructureController(ApplicationStructureBuilder applicationStructureBuilder, RepositoryRestConfiguration configuration, Repositories repositories, ResourceMappings mappings) { Assert.notNull(applicationStructureBuilder, "ApplicationStructureBuilder must not be null!"); Assert.notNull(configuration, "RepositoryRestConfiguration must not be null!"); Assert.notNull(repositories, "Repositories must not be null!"); Assert.notNull(mappings, "ResourceMappings must not be null!"); this.applicationStructureBuilder = applicationStructureBuilder; this.configuration = configuration; this.repositories = repositories; this.mappings = mappings; }
public static PersistentEntity<?,?> findPersistentEntity(Repositories repositories, Class<?> domainType) { PersistentEntity<?, ?> persistentEntity = repositories.getPersistentEntity(domainType); return persistentEntity; }
@PostConstruct public void init() { repositories = new Repositories(applicationContext); repositoryInvokerFactory = new DefaultRepositoryInvokerFactory(repositories, conversionService); }
@PostConstruct public void init() { repositories = new Repositories(context); }
@Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { repositories = new Repositories(applicationContext); }
public static void setRepositories(Repositories repositories) { RepositoryProvider.repositories = repositories; }
public DemoRepositoryEntityLinks(Repositories repositories, ResourceMappings mappings, RepositoryRestConfiguration config, HateoasPageableHandlerMethodArgumentResolver resolver,org.springframework.plugin.core.PluginRegistry<BackendIdConverter,Class<?>> idConverters) { super(repositories, mappings, config, resolver,idConverters); this.resourceMappings = mappings; this.config = config; }
@PostConstruct public void init() { this.repositories = new Repositories(listableBeanFactory); }