├── .classpath ├── .gitignore ├── .project ├── .settings ├── org.eclipse.core.resources.prefs ├── org.eclipse.jdt.core.prefs └── org.eclipse.m2e.core.prefs ├── .springBeans ├── README.md ├── atlassian-ide-plugin.xml ├── documentum ├── cache │ └── 7.1.1000.0037SP1 │ │ └── bof │ │ └── FPIRepo │ │ ├── content.lck │ │ └── content.xml └── identityInterprocessMutex.lock ├── pom.xml ├── spring-data-documentum.iml ├── spring-data-documentum.ipr ├── spring-data-documentum.iws ├── src ├── main │ └── java │ │ └── com │ │ └── emc │ │ └── documentum │ │ └── springdata │ │ ├── core │ │ ├── Application.java │ │ ├── DctmAutoConfiguration.java │ │ ├── DctmOperations.java │ │ ├── DctmTemplate.java │ │ ├── Documentum.java │ │ ├── GenericCache.java │ │ └── exception │ │ │ └── DSException.java │ │ ├── entitymanager │ │ ├── EntityPersistenceManager.java │ │ ├── EntityTypeHandler.java │ │ ├── annotations │ │ │ ├── Content.java │ │ │ ├── Relation.java │ │ │ └── RelationshipType.java │ │ ├── attributes │ │ │ ├── Attribute.java │ │ │ ├── AttributeFactory.java │ │ │ ├── AttributeType.java │ │ │ ├── BooleanAttribute.java │ │ │ ├── BooleanListAttribute.java │ │ │ ├── DoubleAttribute.java │ │ │ ├── DoubleListAttribute.java │ │ │ ├── EntityAttribute.java │ │ │ ├── EntityCollectionAttribute.java │ │ │ ├── IntAttribute.java │ │ │ ├── IntListAttribute.java │ │ │ ├── IterableAttribute.java │ │ │ ├── LongAttribute.java │ │ │ ├── LongListAttribute.java │ │ │ ├── ObjectAttribute.java │ │ │ ├── StringAttribute.java │ │ │ ├── StringListAttribute.java │ │ │ └── TypeUtils.java │ │ ├── convert │ │ │ ├── DCTMToObjectConverter.java │ │ │ └── ObjectToDCTMConverter.java │ │ └── mapping │ │ │ ├── BasicDctmPersistentEntity.java │ │ │ ├── BasicDctmPersistentProperty.java │ │ │ ├── DctmAttribute.java │ │ │ ├── DctmEntity.java │ │ │ ├── DctmMappingContext.java │ │ │ ├── DctmPersistentProperty.java │ │ │ ├── MappingHandler.java │ │ │ └── package-info.java │ │ ├── log │ │ ├── AutowiredLogger.java │ │ └── LoggerInjector.java │ │ ├── repository │ │ ├── DctmRepository.java │ │ ├── DctmRepositoryWithContent.java │ │ ├── Query.java │ │ ├── config │ │ │ ├── AbstractDctmConfiguration.java │ │ │ ├── DctmAttribute.java │ │ │ ├── DctmRepositoriesRegistrar.java │ │ │ ├── DctmRepositoryConfigExtension.java │ │ │ └── EnableDctmRepositories.java │ │ ├── query │ │ │ ├── AbstractDctmQuery.java │ │ │ ├── DctmEntityMetadata.java │ │ │ ├── DctmQuery.java │ │ │ ├── DctmQueryCreator.java │ │ │ ├── DctmQueryMethod.java │ │ │ ├── PartTreeDctmQuery.java │ │ │ ├── SimpleDctmEntityMetadata.java │ │ │ ├── StringBasedDctmQuery.java │ │ │ └── execution │ │ │ │ ├── CollectionExecution.java │ │ │ │ ├── Execution.java │ │ │ │ ├── ModifyingQuery.java │ │ │ │ └── SingleEntityExecution.java │ │ └── support │ │ │ ├── DctmAnnotationProcessor.java │ │ │ ├── DctmContentQuery.java │ │ │ ├── DctmEntityInformation.java │ │ │ ├── DctmQueryLookupStrategy.java │ │ │ ├── DctmRepositoryFactory.java │ │ │ ├── DctmRepositoryFactoryBean.java │ │ │ ├── QueryDslDctmRepository.java │ │ │ ├── QueryDslDctmRepositoryWithContent.java │ │ │ ├── SimpleDctmEntityInformation.java │ │ │ ├── SimpleDctmRepository.java │ │ │ └── SimpleDctmRepositoryWithContent.java │ │ └── security │ │ ├── DocumentumAuthenticationProvider.java │ │ └── SecurityConfiguration.java └── test │ ├── java │ └── com │ │ └── emc │ │ └── documentum │ │ └── springdata │ │ ├── ApplicationConfig.java │ │ ├── LoanQueryDslDctmRepository.java │ │ ├── LoanRepository.java │ │ ├── Person.java │ │ ├── PersonQueryDslRepository.java │ │ ├── PersonRepository.java │ │ ├── core │ │ ├── Address.java │ │ ├── Loan.java │ │ ├── Person.java │ │ └── tests │ │ │ ├── DctmTemplateTest.java │ │ │ ├── DocumentumTest.java │ │ │ └── GenericCacheTest.java │ │ ├── entitymanager │ │ └── mapping │ │ │ └── MappingHandlerTest.java │ │ └── repository │ │ ├── AbstractTest.java │ │ ├── relation │ │ ├── Address.java │ │ ├── Person.java │ │ ├── PersonRepositoryWithRelation.java │ │ ├── RelationTest.java │ │ └── mn │ │ │ ├── Address.java │ │ │ ├── AddressRepository.java │ │ │ ├── ManyToManyRelationTest.java │ │ │ ├── Person.java │ │ │ └── PersonRepositoryWithRelationMn.java │ │ └── support │ │ ├── DctmRepositoryWithContentTest.java │ │ ├── QueryDslDctmRepositoryTest.java │ │ ├── QueryDslDctmRepositoryWithContentTest.java │ │ ├── SimpleDctmRepositoryTest.java │ │ └── StringBasedDctmQueryTest.java │ └── resources │ ├── dfc.properties │ ├── log4j.properties │ └── sample.pdf ├── test.txt └── testsample.pdf /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #*.class 2 | 3 | # Package Files # 4 | *.jar 5 | *.war 6 | *.ear 7 | 8 | # logs 9 | *.log* 10 | /target/* 11 | 12 | 13 | /target/ 14 | /documentum/* 15 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | spring-data-documentum 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.springframework.ide.eclipse.core.springbuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | 25 | org.springframework.ide.eclipse.core.springnature 26 | org.eclipse.jdt.core.javanature 27 | org.eclipse.m2e.core.maven2Nature 28 | 29 | 30 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.7 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 13 | org.eclipse.jdt.core.compiler.source=1.7 14 | -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /.springBeans: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Spring Data for Documentum 2 | Spring data helps a developer remove all the boiler plate code to access a Data repository. 3 | Spring Data for Documentum allows Documentum developers to access Documentum Repository with minimum code. All developers have to write is Domain Class like Person.java or Contact.java and one interface. Spring Data for Documentum takes care of all the CRUD operation for the developer. 4 | 5 | A Spring Data for Documentum Sample can be found [here](https://github.com/waliaraman/spring-data-sample). 6 | 7 | ## Getting Started 8 | 9 | Add Spring Data for Documentum to your pom.xml and youa re ready to go. 10 | ```` 11 | 12 | com.emc.documentum.spring 13 | spring-boot-starter-dctm 14 | 0.0.1 15 | 16 | ```` 17 | 18 | This would ensure that you have all the dependencies needed to get started. As will all Spring Data projects, now all you need is create you domain objects 19 | 20 | ```` 21 | @DctmEntity(repository = "contact") 22 | @Entity(name="contact") 23 | public class Contact { 24 | 25 | @Id 26 | protected String id; 27 | 28 | @DctmAttribute(value="object_name") 29 | private String name; 30 | 31 | public String getId() { 32 | return id; 33 | } 34 | 35 | public void setId(String id) { 36 | this.id = id; 37 | } 38 | 39 | public String getName() { 40 | return name; 41 | } 42 | 43 | public void setName(String name) { 44 | this.name = name; 45 | } 46 | 47 | } 48 | 49 | ```` 50 | 51 | 52 | and expose them using DCTM Repository 53 | 54 | ```` 55 | public interface ContactRepository extends DctmRepositoryWithContent { 56 | 57 | public Iterable findAll(); 58 | 59 | 60 | public Iterable findByNameContaining(String value); 61 | } 62 | 63 | ```` 64 | 65 | This would get you all the CRUD operations for Documentum Repository. 66 | 67 | If the same domain objects is needed to be exposed as a Rest Service, just include the Spring Data Rest dependency in your pom.xml 68 | 69 | ```` 70 | 71 | 72 | 73 | org.springframework.boot 74 | spring-boot-starter-data-rest 75 | 76 | 77 | 78 | org.springframework.data 79 | spring-data-rest-webmvc 80 | 81 | 82 | ```` 83 | 84 | Spring Data for Rest also hooks into Spring Security, so the Authentication would be done against the content server. 85 | 86 | 87 | 88 | ## Built With 89 | 90 | * Maven 91 | 92 | -------------------------------------------------------------------------------- /atlassian-ide-plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /documentum/cache/7.1.1000.0037SP1/bof/FPIRepo/content.lck: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Enterprise-Content-Management/spring-data-dctm/c6bb5cda53d250f1b74b00336322ebaccc788f9d/documentum/cache/7.1.1000.0037SP1/bof/FPIRepo/content.lck -------------------------------------------------------------------------------- /documentum/cache/7.1.1000.0037SP1/bof/FPIRepo/content.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /documentum/identityInterprocessMutex.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Enterprise-Content-Management/spring-data-dctm/c6bb5cda53d250f1b74b00336322ebaccc788f9d/documentum/identityInterprocessMutex.lock -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | com.emc.documentum.spring 6 | spring-data-documentum 7 | jar 8 | 0.0.1 9 | 10 | 11 | 12 | 13 | 14 | UTF-8 15 | UTF-8 16 | 17 | 18 | 1.1.3 19 | 20 | 21 | 3.2.3.RELEASE 22 | 23 | 24 | 4.2.1.Final 25 | 26 | 27 | 1.0.13 28 | 29 | 30 | 4.11 31 | 32 | 3.5.1 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | org.slf4j 41 | slf4j-api 42 | ${slf4j.version} 43 | compile 44 | 45 | 46 | ch.qos.logback 47 | logback-classic 48 | ${logback.version} 49 | runtime 50 | 51 | 52 | 53 | 54 | com.emc.documentum.dfc 55 | dfc 56 | 7.2-20160710.203551-32 57 | 58 | 59 | 60 | 61 | commons-beanutils 62 | commons-beanutils 63 | 1.8.3 64 | 65 | 66 | com.google.guava 67 | guava 68 | 18.0 69 | 70 | 71 | 72 | org.springframework.boot 73 | spring-boot-starter 74 | 1.2.2.RELEASE 75 | 76 | 77 | org.springframework.boot 78 | spring-boot-starter-security 79 | 80 | 81 | org.springframework.boot 82 | spring-boot-starter-test 83 | 1.2.2.RELEASE 84 | 85 | 86 | com.mysema.querydsl 87 | querydsl-mongodb 88 | ${querydsl.version} 89 | true 90 | 91 | 92 | com.mysema.querydsl 93 | querydsl-core 94 | ${querydsl.version} 95 | true 96 | 97 | 98 | com.mysema.querydsl 99 | querydsl-apt 100 | ${querydsl.version} 101 | provided 102 | 103 | 104 | org.springframework.data 105 | spring-data-commons 106 | 1.9.2.RELEASE 107 | 108 | 109 | org.aspectj 110 | aspectjweaver 111 | 1.8.0 112 | 113 | 114 | org.apache.openjpa 115 | openjpa 116 | 2.3.0 117 | 118 | 119 | javax.servlet 120 | javax.servlet-api 121 | 3.0.1 122 | provided 123 | 124 | 125 | 126 | 127 | 128 | com.emc.documentum.spring 129 | https://raw.github.com/mmohen/mvn-repo/gh-pages 130 | 131 | true 132 | 133 | 134 | 135 | 136 | 137 | 138 | org.springframework.boot 139 | spring-boot-starter-parent 140 | 1.2.2.RELEASE 141 | 142 | 143 | 144 | 145 | 146 | ossrh 147 | https://oss.sonatype.org/content/repositories/snapshots 148 | 149 | 150 | ossrh 151 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 152 | 153 | 154 | 155 | 156 | 157 | 158 | org.apache.maven.plugins 159 | maven-compiler-plugin 160 | 161 | 1.7 162 | 1.7 163 | 164 | 165 | 166 | 167 | 168 | com.mysema.maven 169 | apt-maven-plugin 170 | ${apt} 171 | 172 | 173 | com.mysema.querydsl 174 | querydsl-apt 175 | ${querydsl.version} 176 | 177 | 178 | 179 | 180 | generate-test-sources 181 | 182 | test-process 183 | 184 | 185 | target/generated-test-sources 186 | com.emc.documentum.springdata.repository.support.DctmAnnotationProcessor 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | org.apache.maven.plugins 195 | maven-source-plugin 196 | 2.2.1 197 | 198 | 199 | attach-sources 200 | 201 | jar-no-fork 202 | 203 | 204 | 205 | 206 | 207 | org.apache.maven.plugins 208 | maven-javadoc-plugin 209 | 2.9.1 210 | 211 | 212 | attach-javadocs 213 | 214 | jar 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | org.apache.maven.plugins 223 | maven-gpg-plugin 224 | 225 | 226 | sign-artifacts 227 | verify 228 | 229 | sign 230 | 231 | 232 | 233 | 234 | 235 | 236 | org.sonatype.plugins 237 | nexus-staging-maven-plugin 238 | 1.6.7 239 | true 240 | 241 | ossrh 242 | https://oss.sonatype.org/ 243 | true 244 | 526d3a6b674d2 245 | 246 | 247 | 248 | 249 | 250 | 251 | -------------------------------------------------------------------------------- /spring-data-documentum.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/core/Application.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.core; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.ComponentScan; 6 | 7 | import com.documentum.fc.common.DfException; 8 | 9 | @SpringBootApplication 10 | @ComponentScan("com.emc.documentum.springdata") 11 | public class Application { 12 | 13 | public static void main(String[] args) throws DfException { 14 | SpringApplication.run(Application.class); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/core/DctmAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.core; 2 | 3 | import com.emc.documentum.springdata.entitymanager.mapping.DctmMappingContext; 4 | import org.springframework.beans.BeanUtils; 5 | import org.springframework.beans.factory.BeanFactory; 6 | import org.springframework.beans.factory.config.BeanDefinition; 7 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; 10 | import org.springframework.context.annotation.Configuration; 11 | import org.springframework.core.type.filter.AnnotationTypeFilter; 12 | import org.springframework.data.annotation.Persistent; 13 | import org.springframework.data.mapping.model.FieldNamingStrategy; 14 | import org.springframework.util.ClassUtils; 15 | import org.springframework.util.StringUtils; 16 | 17 | import java.util.HashSet; 18 | import java.util.Set; 19 | 20 | /** 21 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 22 | * EMC Confidential: Restricted Internal Distribution 23 | * 24 | * @author Raman Walia 25 | */ 26 | 27 | 28 | @Configuration 29 | public class DctmAutoConfiguration { 30 | 31 | @Bean 32 | @ConditionalOnMissingBean 33 | public DctmMappingContext mongoMappingContext(BeanFactory beanFactory) 34 | throws ClassNotFoundException { 35 | DctmMappingContext context = new DctmMappingContext(); 36 | return context; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/core/DctmOperations.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.core; 2 | 3 | import java.util.List; 4 | 5 | import com.documentum.fc.common.DfException; 6 | import com.emc.documentum.springdata.repository.query.DctmQuery; 7 | 8 | public interface DctmOperations { 9 | 10 | T create(T objectToSave) throws DfException; 11 | 12 | String delete(T objectToDelete) throws DfException; 13 | 14 | String deleteById(ID objectToDeleteId) throws DfException; 15 | 16 | List findAll(Class entityClass) throws DfException; 17 | 18 | List find(DctmQuery query, Class entityClass) throws DfException; 19 | 20 | T findById(String id, Class entityClass) throws DfException; 21 | 22 | T update(T objectToUpdate) throws DfException; 23 | 24 | String getRepositoryObjectName(T obj); 25 | 26 | String getRepositoryName(Class entityClass); 27 | 28 | long count(Class entityClass) throws DfException; 29 | 30 | void setContent(T object, String contentType, String path) throws DfException; 31 | 32 | String getContent(T object, String path) throws DfException; 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/core/DctmTemplate.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.core; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.util.Assert; 8 | 9 | import com.documentum.fc.common.DfException; 10 | import com.emc.documentum.springdata.entitymanager.EntityPersistenceManager; 11 | import com.emc.documentum.springdata.entitymanager.EntityTypeHandler; 12 | import com.emc.documentum.springdata.repository.query.DctmQuery; 13 | 14 | 15 | @Controller 16 | public class DctmTemplate implements DctmOperations { 17 | 18 | private final EntityTypeHandler entityTypeManager; 19 | private final EntityPersistenceManager entityPersistenceManager; 20 | 21 | @Autowired 22 | public DctmTemplate(EntityPersistenceManager entityPersistenceManager, EntityTypeHandler entityTypeManager) { 23 | this.entityPersistenceManager = entityPersistenceManager; 24 | this.entityTypeManager = entityTypeManager; 25 | } 26 | 27 | @Override 28 | public T create(T objectToSave) throws DfException { 29 | Assert.notNull(objectToSave); 30 | String repoObjectName = getRepositoryObjectName(objectToSave); 31 | return entityPersistenceManager.createObject(repoObjectName, objectToSave); 32 | } 33 | 34 | @Override 35 | public String delete(T objectToDelete) throws DfException { 36 | Assert.notNull(objectToDelete); 37 | String repoObjectName = getRepositoryObjectName(objectToDelete); 38 | return entityPersistenceManager.deleteObject(repoObjectName, objectToDelete); 39 | } 40 | 41 | @Override 42 | public String deleteById(ID objectToDeleteId) throws DfException { 43 | Assert.notNull(objectToDeleteId); 44 | return entityPersistenceManager.deleteObject(objectToDeleteId.toString()); 45 | } 46 | 47 | @Override 48 | public List findAll(Class entityClass) throws DfException { 49 | return find(null, entityClass); 50 | } 51 | 52 | @Override 53 | public List find(DctmQuery query, Class entityClass) throws DfException { 54 | Assert.notNull(entityClass); 55 | String repoObjectName = getRepositoryName(entityClass); 56 | return query == null ? doFindAll(entityClass, repoObjectName) : entityPersistenceManager.find(entityClass, repoObjectName, query); 57 | } 58 | 59 | private List doFindAll(Class entityClass, String repoObjectName) throws DfException { 60 | return entityPersistenceManager.findAllObjects(entityClass, repoObjectName); 61 | } 62 | 63 | @Override 64 | public T findById(String id, Class entityClass) throws DfException { 65 | Assert.notNull(id); 66 | Assert.notNull(entityClass); 67 | return entityPersistenceManager.findById(id, entityClass); 68 | } 69 | 70 | @Override 71 | public long count(Class entityClass) throws DfException { 72 | Assert.notNull(entityClass); 73 | String repoObjectName = getRepositoryName(entityClass); 74 | return entityPersistenceManager.count(entityClass, repoObjectName); 75 | } 76 | 77 | @Override 78 | public T update(T objectToUpdate) throws DfException { 79 | return entityPersistenceManager.update(objectToUpdate); 80 | } 81 | 82 | @Override 83 | public String getRepositoryObjectName(T obj) { 84 | Assert.notNull(obj); 85 | return getRepositoryName(obj.getClass()); 86 | } 87 | 88 | @Override 89 | public String getRepositoryName(Class entityClass) { 90 | Assert.notNull(entityClass); 91 | return entityTypeManager.getEntityObjectName(entityClass); 92 | } 93 | 94 | @Override 95 | public void setContent(T object, String contentType, String path) throws DfException { 96 | entityPersistenceManager.setContent(object, contentType, path); 97 | } 98 | 99 | @Override 100 | public String getContent(T object, String path) throws DfException { 101 | return entityPersistenceManager.getContent(object, path); 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/core/Documentum.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.core; 2 | 3 | import org.apache.log4j.Logger; 4 | import org.springframework.data.authentication.UserCredentials; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.util.Assert; 7 | 8 | import com.documentum.com.DfClientX; 9 | import com.documentum.fc.client.IDfClient; 10 | import com.documentum.fc.client.IDfSession; 11 | import com.documentum.fc.client.IDfSessionManager; 12 | import com.documentum.fc.client.IDfTypedObject; 13 | import com.documentum.fc.common.DfException; 14 | import com.documentum.fc.common.IDfLoginInfo; 15 | 16 | @Controller 17 | public class Documentum { 18 | 19 | private Logger logger = Logger.getLogger(Documentum.class); 20 | private UserCredentials credentials; 21 | private String docBase; 22 | private IDfSessionManager sessionManager; 23 | 24 | 25 | public Documentum() { 26 | } 27 | 28 | public void setCredentials(UserCredentials credentials) { 29 | this.credentials = credentials; 30 | } 31 | 32 | public void setDocBase(String docBase) { 33 | this.docBase = docBase; 34 | } 35 | 36 | public UserCredentials getCredentials() { 37 | return this.credentials; 38 | } 39 | 40 | 41 | public Documentum(UserCredentials credentials, String docBase, String docbrokerHost, String docbrokerPort) 42 | throws DfException { 43 | 44 | Assert.notNull(credentials); 45 | Assert.notNull(docBase); 46 | 47 | this.credentials = credentials; 48 | this.docBase = docBase; 49 | 50 | createSessionManager(credentials, docbrokerHost, docbrokerPort); 51 | } 52 | 53 | private void createSessionManager(UserCredentials credentials, String docbrokerHost, String docbrokerPort) throws DfException { 54 | DfClientX clientX = new DfClientX(); 55 | IDfClient client = clientX.getLocalClient(); 56 | IDfTypedObject config = client.getClientConfig(); 57 | 58 | if (docbrokerHost != null && docbrokerPort != null) { 59 | config.setString("primary_host", docbrokerHost); 60 | config.setInt("primary_port", new Integer(docbrokerPort)); 61 | } 62 | 63 | this.sessionManager = client.newSessionManager(); 64 | IDfLoginInfo loginInfo = clientX.getLoginInfo(); 65 | loginInfo.setUser(credentials.getUsername()); 66 | loginInfo.setPassword(credentials.getPassword()); 67 | sessionManager.setIdentity(IDfSessionManager.ALL_DOCBASES, loginInfo); 68 | logger.info("Session Manager Created"); 69 | } 70 | 71 | 72 | public IDfSession getSession() throws DfException { 73 | if (sessionManager == null) { 74 | logger.info("Creating session manager"); 75 | createSessionManager(this.credentials, null, null); 76 | logger.info("Created session manager"); 77 | } 78 | 79 | try { 80 | return this.sessionManager.getSession(this.docBase); 81 | } catch (Exception e) { 82 | String msg = String.format( 83 | "Session cannot be instantiated for user %s for docBase %s. " + "Exception: %s, %s.", this.credentials.getUsername(), docBase, e.getClass(), 84 | e.getMessage() 85 | ); 86 | logger.error(msg); 87 | throw new DfException(msg, e); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/core/GenericCache.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.core; 2 | 3 | import com.google.common.cache.CacheBuilder; 4 | import com.google.common.cache.Cache; 5 | 6 | import java.util.concurrent.TimeUnit; 7 | 8 | public class GenericCache { 9 | 10 | private static Cache< Object, Object > cache; 11 | 12 | public GenericCache() { 13 | createCache(); 14 | } 15 | 16 | private synchronized void createCache() { 17 | if(cache == null){ 18 | cache = CacheBuilder.newBuilder() 19 | .concurrencyLevel(4) 20 | .maximumSize(10000) 21 | .expireAfterWrite(10, TimeUnit.MINUTES) 22 | .build(); 23 | } 24 | } 25 | 26 | public Object getEntry( Object key ) { 27 | try { 28 | return cache.getIfPresent( key ); 29 | } catch (Exception e) { 30 | return null; 31 | } 32 | } 33 | 34 | public void setEntry(Object key, Object value){ 35 | cache.asMap().put(key, value); 36 | } 37 | } 38 | 39 | //TODO: take all the concurrency properties for the user from a property file 40 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/core/exception/DSException.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.core.exception; 2 | 3 | /** 4 | * Created with IntelliJ IDEA. 5 | * User: ramanwalia 6 | * Date: 26/02/15 7 | * Time: 10:07 AM 8 | * To change this template use File | Settings | File Templates. 9 | */ 10 | public class DSException extends Exception { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/EntityTypeHandler.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager; 2 | 3 | import org.springframework.core.annotation.AnnotationUtils; 4 | import org.springframework.stereotype.Component; 5 | import org.springframework.util.Assert; 6 | import org.springframework.util.StringUtils; 7 | 8 | import com.emc.documentum.springdata.entitymanager.mapping.DctmEntity; 9 | 10 | @Component 11 | public class EntityTypeHandler { 12 | 13 | public String getEntityObjectName(Class entityClass) { 14 | Assert.notNull(entityClass, "No class parameter provided, entity collection can't be determined!"); 15 | return getEntityObjectNameFromClass(entityClass); 16 | } 17 | 18 | public String getEntityObjectNameFromClass(Class type) { 19 | DctmEntity dctmObject = AnnotationUtils.findAnnotation(type, DctmEntity.class); 20 | return StringUtils.isEmpty(dctmObject.repository()) ? type.getSimpleName() : dctmObject.repository(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/annotations/Content.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.annotations; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | 7 | /** 8 | *  * Annotation to indicate Content for dn_document DCTMObject. 9 | *   10 | */ 11 | 12 | @Documented 13 | @Retention(RetentionPolicy.RUNTIME) 14 | public @interface Content { 15 | 16 | /** 17 | * The method to be performed on the content can either be "get" or "set". 18 | * 19 | */ 20 | 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/annotations/Relation.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Created with IntelliJ IDEA. 10 | * User: ramanwalia 11 | * Date: 20/03/15 12 | * Time: 9:30 PM 13 | * To change this template use File | Settings | File Templates. 14 | */ 15 | 16 | @Retention(RetentionPolicy.RUNTIME) 17 | @Target(ElementType.FIELD) 18 | public @interface Relation { 19 | RelationshipType value() default RelationshipType.ONE_TO_ONE; 20 | 21 | String name(); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/annotations/RelationshipType.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.annotations; 2 | 3 | /* 4 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 5 | * EMC Confidential: Restricted Internal Distribution 6 | */ 7 | public enum RelationshipType{ 8 | ONE_TO_MANY, ONE_TO_ONE 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/attributes/Attribute.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.attributes; 2 | 3 | import com.documentum.fc.common.DfException; 4 | 5 | public abstract class Attribute { 6 | 7 | protected int dfAttributeType; 8 | public String name; 9 | 10 | public int getDfAttributeType() { 11 | return dfAttributeType; 12 | } 13 | 14 | public Attribute(String name) { 15 | this.name = name; 16 | } 17 | 18 | public String getName() { 19 | return this.name; 20 | } 21 | 22 | public abstract T getValue(Object o) throws DfException; 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/attributes/AttributeFactory.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.attributes; 2 | 3 | import static com.emc.documentum.springdata.entitymanager.attributes.TypeUtils.isBoolean; 4 | import static com.emc.documentum.springdata.entitymanager.attributes.TypeUtils.isCollection; 5 | import static com.emc.documentum.springdata.entitymanager.attributes.TypeUtils.isDouble; 6 | import static com.emc.documentum.springdata.entitymanager.attributes.TypeUtils.isInteger; 7 | import static com.emc.documentum.springdata.entitymanager.attributes.TypeUtils.isLong; 8 | import static com.emc.documentum.springdata.entitymanager.attributes.TypeUtils.isString; 9 | 10 | import java.lang.reflect.Field; 11 | import java.lang.reflect.ParameterizedType; 12 | import java.lang.reflect.Type; 13 | 14 | import com.emc.documentum.springdata.entitymanager.annotations.Relation; 15 | 16 | 17 | public class AttributeFactory { 18 | 19 | public static Attribute getAttribute(Field field, String attributeName) { 20 | Class type = field.getType(); 21 | 22 | if(isRelation(field)) { 23 | return getAttributeAsRelation(field, attributeName); 24 | } else if (isString(type)) { 25 | return new StringAttribute(attributeName); 26 | } else if (isInteger(type)) { 27 | return new IntAttribute(attributeName); 28 | } else if (isDouble(type)) { 29 | return new DoubleAttribute(attributeName); 30 | } else if (isLong(type)) { 31 | return new LongAttribute(attributeName); 32 | } else if (isBoolean(type)) { 33 | return new BooleanAttribute(attributeName); 34 | } else if (isCollection(type) && isString(getParameterizedType(field))) { 35 | return new StringListAttribute(attributeName); 36 | } else if (isCollection(type) && isInteger(getParameterizedType(field))) { 37 | return new IntListAttribute(attributeName); 38 | } else if (isCollection(type) && isDouble(getParameterizedType(field))) { 39 | return new DoubleListAttribute(attributeName); 40 | } else if (isCollection(type) && isLong(getParameterizedType(field))) { 41 | return new LongListAttribute(attributeName); 42 | } else if (isCollection(type) && isBoolean(getParameterizedType(field))) { 43 | return new BooleanListAttribute(attributeName); 44 | } 45 | return null; 46 | } 47 | 48 | private static Attribute getAttributeAsRelation(Field field, String attributeName) { 49 | if(isCollection(field.getType())) { 50 | return new EntityCollectionAttribute<>(attributeName); 51 | } else { 52 | return new EntityAttribute<>(attributeName); 53 | } 54 | } 55 | 56 | private static boolean isRelation(Field field) { 57 | return field.getAnnotation(Relation.class) != null; 58 | } 59 | 60 | private static Type getParameterizedType(Field field) { 61 | field.setAccessible(true); 62 | return ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/attributes/AttributeType.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.attributes; 2 | 3 | import com.emc.documentum.springdata.entitymanager.annotations.RelationshipType; 4 | 5 | public class AttributeType { 6 | 7 | private final String fieldName; 8 | private final Attribute attribute; 9 | private final boolean isRelation; 10 | private final String relationName; 11 | private final RelationshipType relationshipType; 12 | private final Class relatedEntityClass; 13 | 14 | public AttributeType(String fieldName, Attribute attribute) { 15 | this(fieldName, attribute, false, "", null, null); 16 | } 17 | 18 | public AttributeType( 19 | String fieldName, Attribute attribute, boolean isRelation, String relationName, RelationshipType relationshipType, Class relatedEntityClass 20 | ) { 21 | this.fieldName = fieldName; 22 | this.attribute = attribute; 23 | this.isRelation = isRelation; 24 | this.relationName = relationName; 25 | this.relationshipType = relationshipType; 26 | this.relatedEntityClass = relatedEntityClass; 27 | } 28 | 29 | public String getFieldName() { 30 | return this.fieldName; 31 | } 32 | 33 | public Attribute getAttribute() { 34 | return this.attribute; 35 | } 36 | 37 | public boolean isRelation() { 38 | return isRelation; 39 | } 40 | 41 | public String getRelationName() { 42 | return relationName; 43 | } 44 | 45 | public Class getRelatedEntityClass() { 46 | return relatedEntityClass; 47 | } 48 | 49 | public RelationshipType getRelationshipType() { 50 | return relationshipType; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return "AttributeType{" + 56 | "fieldName='" + fieldName + '\'' + 57 | ", attribute=" + attribute + 58 | ", isRelation=" + isRelation + 59 | ", relationName='" + relationName + '\'' + 60 | ", relationshipType=" + relationshipType + 61 | ", relatedEntityClass=" + relatedEntityClass + 62 | '}'; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/attributes/BooleanAttribute.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.attributes; 2 | 3 | import com.documentum.fc.client.IDfTypedObject; 4 | import com.documentum.fc.common.DfException; 5 | 6 | public class BooleanAttribute extends Attribute { 7 | 8 | public BooleanAttribute(String name) { 9 | super(name); 10 | dfAttributeType = 0; 11 | } 12 | 13 | @Override 14 | public Boolean getValue(Object o) throws DfException { 15 | return ((IDfTypedObject) o).getBoolean(name); 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/attributes/BooleanListAttribute.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.attributes; 2 | 3 | import com.documentum.fc.client.IDfSysObject; 4 | import com.documentum.fc.client.IDfTypedObject; 5 | import com.documentum.fc.common.DfException; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | 11 | public class BooleanListAttribute extends IterableAttribute> { 12 | 13 | public BooleanListAttribute(java.lang.String name) { 14 | super(name); 15 | } 16 | 17 | @Override 18 | public List getValue(Object o) throws DfException { 19 | List values = new ArrayList(); 20 | IDfTypedObject obj = (IDfTypedObject) o; 21 | int size = obj.getValueCount(name); 22 | 23 | for (int i = 0 ; i < size; i++) 24 | values.add(obj.getRepeatingBoolean(name,i)); 25 | 26 | return values; 27 | } 28 | 29 | @Override 30 | public void setValue(IDfSysObject dctmObject, List valueToSet) throws DfException { 31 | 32 | dctmObject.removeAll(name); 33 | 34 | for (int i = 0; i < valueToSet.size(); i++) { 35 | dctmObject.setRepeatingBoolean(name, i, (Boolean) valueToSet.get(i)); 36 | } 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/attributes/DoubleAttribute.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.attributes; 2 | 3 | import com.documentum.fc.client.IDfTypedObject; 4 | import com.documentum.fc.common.DfException; 5 | 6 | public class DoubleAttribute extends Attribute { 7 | 8 | public DoubleAttribute(String name) { 9 | super(name); 10 | dfAttributeType = 5; 11 | } 12 | 13 | @Override 14 | public Double getValue(Object o) throws DfException { 15 | return ((IDfTypedObject) o).getDouble(name); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/attributes/DoubleListAttribute.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.attributes; 2 | 3 | import com.documentum.fc.client.IDfSysObject; 4 | import com.documentum.fc.client.IDfTypedObject; 5 | import com.documentum.fc.common.DfException; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | 11 | public class DoubleListAttribute extends IterableAttribute> { 12 | 13 | public DoubleListAttribute(java.lang.String name) { 14 | super(name); 15 | } 16 | 17 | @Override 18 | public List getValue(Object o) throws DfException { 19 | List values = new ArrayList(); 20 | IDfTypedObject obj = (IDfTypedObject) o; 21 | int size = obj.getValueCount(name); 22 | 23 | for (int i = 0 ; i < size; i++) 24 | values.add(obj.getRepeatingDouble(name,i)); 25 | 26 | return values; 27 | } 28 | 29 | @Override 30 | public void setValue(IDfSysObject dctmObject, List valueToSet) throws DfException { 31 | 32 | dctmObject.removeAll(name); 33 | 34 | for (int i = 0; i < valueToSet.size(); i++) { 35 | dctmObject.setRepeatingDouble(name, i, (Double) valueToSet.get(i)); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/attributes/EntityAttribute.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.attributes; 2 | 3 | import com.documentum.fc.common.DfException; 4 | 5 | /* 6 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 7 | * EMC Confidential: Restricted Internal Distribution 8 | */ 9 | public class EntityAttribute extends Attribute { 10 | 11 | public EntityAttribute(String name) { 12 | super(name); 13 | } 14 | 15 | @Override 16 | public T getValue(Object o) throws DfException { 17 | return null; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/attributes/EntityCollectionAttribute.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.attributes; 2 | 3 | import java.util.List; 4 | 5 | import com.documentum.fc.client.IDfSysObject; 6 | import com.documentum.fc.common.DfException; 7 | 8 | /* 9 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 10 | * EMC Confidential: Restricted Internal Distribution 11 | */ 12 | public class EntityCollectionAttribute extends IterableAttribute { 13 | 14 | public EntityCollectionAttribute(String name) { 15 | super(name); 16 | } 17 | 18 | @Override 19 | public void setValue(IDfSysObject dctmObject, List valueToSet) throws DfException { 20 | 21 | } 22 | 23 | @Override 24 | public T getValue(Object o) throws DfException { 25 | return null; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/attributes/IntAttribute.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.attributes; 2 | 3 | import com.documentum.fc.client.IDfTypedObject; 4 | import com.documentum.fc.common.DfException; 5 | 6 | public class IntAttribute extends Attribute { 7 | 8 | public IntAttribute(String name) { 9 | super(name); 10 | dfAttributeType = 1; 11 | } 12 | 13 | @Override 14 | public Integer getValue(Object o) throws DfException { 15 | return ((IDfTypedObject) o).getInt(name); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/attributes/IntListAttribute.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.attributes; 2 | 3 | import com.documentum.fc.client.IDfSysObject; 4 | import com.documentum.fc.client.IDfTypedObject; 5 | import com.documentum.fc.common.DfException; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | 11 | public class IntListAttribute extends IterableAttribute> { 12 | 13 | public IntListAttribute(java.lang.String name) { 14 | super(name); 15 | } 16 | 17 | @Override 18 | public List getValue(Object o) throws DfException { 19 | List values = new ArrayList(); 20 | IDfTypedObject obj = (IDfTypedObject) o; 21 | int size = obj.getValueCount(name); 22 | 23 | for (int i = 0 ; i < size; i++) 24 | values.add(obj.getRepeatingInt(name,i)); 25 | 26 | return values; 27 | } 28 | 29 | @Override 30 | public void setValue(IDfSysObject dctmObject, List valueToSet) throws DfException { 31 | 32 | dctmObject.removeAll(name); 33 | 34 | for (int i = 0; i < valueToSet.size(); i++) { 35 | dctmObject.setRepeatingInt(name, i, (Integer) valueToSet.get(i)); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/attributes/IterableAttribute.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.attributes; 2 | 3 | import java.util.List; 4 | 5 | import com.documentum.fc.client.IDfSysObject; 6 | import com.documentum.fc.common.DfException; 7 | 8 | public abstract class IterableAttribute extends Attribute { 9 | 10 | public IterableAttribute(String name) { 11 | super(name); 12 | } 13 | 14 | public abstract void setValue(IDfSysObject dctmObject, List valueToSet) throws DfException; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/attributes/LongAttribute.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.attributes; 2 | 3 | import com.documentum.fc.client.IDfTypedObject; 4 | import com.documentum.fc.common.DfException; 5 | 6 | public class LongAttribute extends Attribute { 7 | 8 | public LongAttribute(String name) { 9 | super(name); 10 | dfAttributeType = 5; 11 | } 12 | 13 | @Override 14 | public Long getValue(Object o) throws DfException { 15 | return ((IDfTypedObject) o).getLong(name); 16 | 17 | } 18 | } -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/attributes/LongListAttribute.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.attributes; 2 | 3 | import com.documentum.fc.client.IDfSysObject; 4 | import com.documentum.fc.client.IDfTypedObject; 5 | import com.documentum.fc.common.DfException; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | public class LongListAttribute extends IterableAttribute> { 11 | 12 | public LongListAttribute(java.lang.String name) { 13 | super(name); 14 | } 15 | 16 | @Override 17 | public List getValue(Object o) throws DfException { 18 | List values = new ArrayList(); 19 | IDfTypedObject obj = (IDfTypedObject) o; 20 | int size = obj.getValueCount(name); 21 | 22 | for (int i = 0 ; i < size; i++) 23 | values.add(obj.getRepeatingLong(name,i)); 24 | 25 | return values; 26 | } 27 | 28 | @Override 29 | public void setValue(IDfSysObject dctmObject, List valueToSet) throws DfException { 30 | 31 | dctmObject.removeAll(name); 32 | 33 | for (int i = 0; i < valueToSet.size(); i++) { 34 | //TODO : no setRepeatingLong, this conversion works right? 35 | dctmObject.setRepeatingDouble(name, i, (Double) valueToSet.get(i)); 36 | } 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/attributes/ObjectAttribute.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.attributes; 2 | 3 | import com.documentum.fc.common.DfException; 4 | 5 | public class ObjectAttribute extends Attribute { 6 | 7 | public ObjectAttribute(String name) { 8 | super(name); 9 | } 10 | 11 | @Override 12 | public Object getValue(Object o) throws DfException { 13 | return null; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/attributes/StringAttribute.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.attributes; 2 | 3 | import com.documentum.fc.client.IDfTypedObject; 4 | import com.documentum.fc.common.DfException; 5 | 6 | public class StringAttribute extends Attribute { 7 | 8 | public StringAttribute(String name) { 9 | super(name); 10 | dfAttributeType = 2; 11 | } 12 | 13 | 14 | @Override 15 | public String getValue(Object o) throws DfException { 16 | return ((IDfTypedObject) o).getString(name); 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/attributes/StringListAttribute.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.attributes; 2 | 3 | import com.documentum.fc.client.IDfSysObject; 4 | import com.documentum.fc.client.IDfTypedObject; 5 | import com.documentum.fc.common.DfException; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | public class StringListAttribute extends IterableAttribute> { 11 | 12 | public StringListAttribute(java.lang.String name) { 13 | super(name); 14 | dfAttributeType = 2; 15 | } 16 | 17 | @Override 18 | public List getValue(Object o) throws DfException { 19 | List values = new ArrayList(); 20 | IDfTypedObject obj = (IDfTypedObject) o; 21 | int size = obj.getValueCount(name); 22 | 23 | for (int i = 0 ; i < size; i++) 24 | values.add(obj.getRepeatingString(name,i)); 25 | 26 | return values; 27 | } 28 | 29 | @Override 30 | public void setValue(IDfSysObject dctmObject, List valueToSet) throws DfException { 31 | 32 | dctmObject.removeAll(name); 33 | for (int i = 0; i < valueToSet.size(); i++) { 34 | dctmObject.setRepeatingString(name, i, (String) valueToSet.get(i)); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/attributes/TypeUtils.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.attributes; 2 | 3 | import java.lang.reflect.Type; 4 | import java.util.Collection; 5 | 6 | /* 7 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 8 | * EMC Confidential: Restricted Internal Distribution 9 | */ 10 | public class TypeUtils { 11 | public static boolean isBoolean(Class type) {return type == Boolean.class || type == boolean.class;} 12 | 13 | public static boolean isLong(Class type) {return type == Long.class || type == long.class;} 14 | 15 | public static boolean isDouble(Class type) {return type == Double.class || type == double.class;} 16 | 17 | public static boolean isInteger(Class type) {return type == Integer.class || type == int.class;} 18 | 19 | public static boolean isString(Class type) {return type == String.class;} 20 | 21 | public static boolean isCollection(Class type) {return Collection.class.isAssignableFrom(type);} 22 | 23 | public static boolean isBoolean(Type type) {return type == Boolean.class || type == boolean.class;} 24 | 25 | public static boolean isLong(Type type) {return type == Long.class || type == long.class;} 26 | 27 | public static boolean isDouble(Type type) {return type == Double.class || type == double.class;} 28 | 29 | public static boolean isInteger(Type type) {return type == Integer.class || type == int.class;} 30 | 31 | public static boolean isString(Type type) {return type == String.class;} 32 | 33 | public static boolean isCollection(Type type) {return Collection.class.isAssignableFrom((Class)type);} 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/convert/DCTMToObjectConverter.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.convert; 2 | 3 | import java.lang.reflect.Field; 4 | import java.lang.reflect.InvocationTargetException; 5 | import java.util.ArrayList; 6 | import java.util.HashMap; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | import org.apache.commons.beanutils.PropertyUtils; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.data.annotation.Id; 13 | import org.springframework.stereotype.Controller; 14 | import org.springframework.util.ReflectionUtils; 15 | 16 | import com.documentum.fc.client.DfQuery; 17 | import com.documentum.fc.client.IDfCollection; 18 | import com.documentum.fc.client.IDfPersistentObject; 19 | import com.documentum.fc.client.IDfQuery; 20 | import com.documentum.fc.client.IDfTypedObject; 21 | import com.documentum.fc.common.DfException; 22 | import com.documentum.fc.common.DfId; 23 | import com.emc.documentum.springdata.entitymanager.attributes.Attribute; 24 | import com.emc.documentum.springdata.entitymanager.attributes.AttributeType; 25 | import com.emc.documentum.springdata.entitymanager.mapping.MappingHandler; 26 | 27 | @Controller 28 | public class DCTMToObjectConverter { 29 | 30 | public static final String SELECT_RELATION_QUERY = 31 | "select * from dm_relation where relation_name=\'%s\' and (parent_id=\'%s\' or " + "child_id=\'%s\')"; 32 | @Autowired 33 | MappingHandler mappingHandler; 34 | private Map objectsBeingConverted = new HashMap<>(); 35 | 36 | public DCTMToObjectConverter() {} 37 | 38 | public void convert(IDfTypedObject dctmObject, Object objectToReturn, ArrayList mapping) throws DfException { 39 | objectsBeingConverted = new HashMap<>(); 40 | doConvert(dctmObject, objectToReturn, mapping); 41 | } 42 | 43 | @SuppressWarnings("unchecked") 44 | private void doConvert(IDfTypedObject dctmObject, Object objectToReturn, ArrayList mapping) throws DfException { 45 | setNonRelationalAttributes(dctmObject, objectToReturn, mapping); 46 | 47 | setRelationalAttributes(dctmObject, objectToReturn, mapping); 48 | } 49 | 50 | private void setNonRelationalAttributes(IDfTypedObject dctmObject, Object objectToReturn, ArrayList mapping) throws DfException { 51 | for (AttributeType attributeType : mapping) { 52 | try { 53 | if (!attributeType.isRelation()) { 54 | System.out.println(attributeType); 55 | getValue(dctmObject, objectToReturn, attributeType); 56 | } 57 | } catch (Exception e) { 58 | String msg = String.format( 59 | "Conversion failed for Object of class %s. " + "Exception: %s, %s.", objectToReturn.getClass(), e.getClass(), e.getMessage()); 60 | System.out.println("Failed for "); 61 | throw new DfException(msg, e); 62 | } 63 | } 64 | } 65 | 66 | private void setRelationalAttributes(IDfTypedObject dctmObject, Object objectToReturn, ArrayList mapping) throws DfException { 67 | 68 | if (objectsBeingConverted.get(getId(objectToReturn)) == null) { 69 | objectsBeingConverted.put(getId(objectToReturn), objectToReturn); 70 | } 71 | for (AttributeType attributeType : mapping) { 72 | if (attributeType.isRelation()) { 73 | populateRelatedObjects(dctmObject, objectToReturn, attributeType); 74 | } 75 | } 76 | } 77 | 78 | //TODO: get*** method should return something, change method name. 79 | @SuppressWarnings("unchecked") 80 | private void populateRelatedObjects(IDfTypedObject dctmObject, Object objectToReturn, AttributeType attributeType) throws DfException { 81 | try { 82 | IDfCollection relations = getRelationObjects(dctmObject, attributeType); 83 | setRelatedObjects(dctmObject, objectToReturn, attributeType, relations); 84 | } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { 85 | throw new DfException(e); 86 | } 87 | } 88 | 89 | private IDfCollection getRelationObjects(IDfTypedObject dctmObject, AttributeType attributeType) throws DfException { 90 | String objectId = dctmObject.getString("r_object_id"); 91 | String relationQuery = String.format(SELECT_RELATION_QUERY, attributeType.getRelationName(), objectId, objectId); 92 | System.out.println(String.format("Executing query \r\n %s \r\n", relationQuery)); 93 | 94 | IDfQuery query = new DfQuery(relationQuery); 95 | return query.execute(dctmObject.getSession(), 0); 96 | } 97 | 98 | private void setRelatedObjects(IDfTypedObject dctmObject, Object objectToReturn, AttributeType attributeType, IDfCollection relations) 99 | throws DfException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { 100 | 101 | switch (attributeType.getRelationshipType()) { 102 | case ONE_TO_MANY: 103 | setChildren(dctmObject, objectToReturn, attributeType, relations); 104 | break; 105 | case ONE_TO_ONE: 106 | setChild(dctmObject, objectToReturn, attributeType, relations); 107 | break; 108 | } 109 | } 110 | 111 | //TODO: Fix code duplication in setChild and setChildren 112 | @SuppressWarnings("unchecked") 113 | private void setChild(IDfTypedObject dctmObject, Object objectToReturn, AttributeType attributeType, IDfCollection relation) 114 | throws DfException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { 115 | 116 | if (relation.next()) { 117 | String relatedObjectId = getId(objectToReturn).equalsIgnoreCase(relation.getString("child_id")) ? relation.getString("parent_id") : relation 118 | .getString("child_id"); 119 | 120 | if (objectsBeingConverted.get(relatedObjectId) == null) { 121 | IDfTypedObject child = relation.getTypedObject(); 122 | IDfPersistentObject childObject = dctmObject.getSession().getObject(new DfId(child.getString("child_id"))); 123 | Object relatedEntityInstance = attributeType.getRelatedEntityClass().newInstance(); 124 | 125 | doConvert(childObject, relatedEntityInstance, mappingHandler.getAttributeMappings(relatedEntityInstance)); 126 | PropertyUtils.setSimpleProperty(objectToReturn, attributeType.getFieldName(), relatedEntityInstance); 127 | } else { 128 | PropertyUtils.setSimpleProperty(objectToReturn, attributeType.getFieldName(), objectsBeingConverted.get(relatedObjectId)); 129 | } 130 | } 131 | } 132 | 133 | @SuppressWarnings("unchecked") 134 | private void setChildren(IDfTypedObject dctmObject, Object objectToReturn, AttributeType attributeType, IDfCollection relations) 135 | throws DfException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { 136 | 137 | List childrenList = new ArrayList(); 138 | 139 | while (relations.next()) { 140 | IDfTypedObject relation = relations.getTypedObject(); 141 | String relatedObjectId = getId(objectToReturn).equalsIgnoreCase(relation.getString("child_id")) ? relation.getString("parent_id") : relation 142 | .getString("child_id"); 143 | 144 | if (objectsBeingConverted.get(relatedObjectId) == null) { 145 | IDfPersistentObject childObject = dctmObject.getSession().getObject(new DfId(relatedObjectId)); 146 | 147 | String childObjectType = childObject.getString("r_object_type"); 148 | System.out.println(String.format("Child object type: {%s}", childObjectType)); 149 | 150 | Object relatedEntityInstance = attributeType.getRelatedEntityClass().newInstance(); 151 | doConvert(childObject, relatedEntityInstance, mappingHandler.getAttributeMappings(relatedEntityInstance)); 152 | childrenList.add(relatedEntityInstance); 153 | objectsBeingConverted.put(relatedObjectId, relatedEntityInstance); 154 | } else { 155 | childrenList.add(objectsBeingConverted.get(relatedObjectId)); 156 | } 157 | } 158 | 159 | PropertyUtils.setSimpleProperty(objectToReturn, attributeType.getFieldName(), childrenList); 160 | } 161 | 162 | private String getId(T objectToSave) throws DfException { 163 | Field[] fields = mappingHandler.getFields(objectToSave.getClass()); 164 | String id = ""; 165 | for (Field field : fields) { 166 | field.setAccessible(true); 167 | if (field.getAnnotation(Id.class) != null) { 168 | id = (String)ReflectionUtils.getField(field, objectToSave); 169 | } 170 | } 171 | return id; 172 | } 173 | 174 | private void getValue(IDfTypedObject dctmObject, Object objectToReturn, AttributeType fieldType) 175 | throws DfException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { 176 | Attribute attribute = fieldType.getAttribute(); 177 | Object attributeValue = attribute.getValue(dctmObject); 178 | PropertyUtils.setSimpleProperty(objectToReturn, fieldType.getFieldName(), attributeValue); 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/convert/ObjectToDCTMConverter.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.convert; 2 | 3 | import java.lang.reflect.InvocationTargetException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | 8 | import com.documentum.fc.common.DfValue; 9 | import com.documentum.fc.common.IDfValue; 10 | 11 | import org.apache.commons.beanutils.PropertyUtils; 12 | import org.springframework.stereotype.Controller; 13 | 14 | import com.documentum.fc.client.IDfSysObject; 15 | import com.documentum.fc.common.DfException; 16 | import com.emc.documentum.springdata.entitymanager.attributes.Attribute; 17 | import com.emc.documentum.springdata.entitymanager.attributes.AttributeType; 18 | import com.emc.documentum.springdata.entitymanager.attributes.IterableAttribute; 19 | 20 | @Controller 21 | public class ObjectToDCTMConverter { 22 | 23 | public ObjectToDCTMConverter() {} 24 | 25 | public void convert(Object objectToSave, IDfSysObject dctmObject, ArrayList mapping) throws DfException { 26 | for (AttributeType attributeType : mapping) { 27 | if (!shouldIgnore(attributeType)) { 28 | try { 29 | setValue(dctmObject, objectToSave, attributeType); 30 | } catch (Exception e) { 31 | String msg = String.format("Conversion failed for Object of class %s. " + "Exception: %s, %s.", 32 | objectToSave.getClass(), e.getClass(), e.getMessage()); 33 | throw new DfException(msg, e); 34 | } 35 | } 36 | } 37 | } 38 | 39 | private boolean shouldIgnore(AttributeType attributeType) { 40 | return attributeType.getAttribute().getName().equals( "r_object_id") || attributeType.isRelation(); 41 | } 42 | 43 | private void setValue(IDfSysObject dctmObject, Object objectToSave, AttributeType fieldType) 44 | throws DfException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { 45 | 46 | Object valueFromClass = PropertyUtils.getSimpleProperty(objectToSave, fieldType.getFieldName()); 47 | 48 | if(valueFromClass != null) { 49 | 50 | Attribute attribute = fieldType.getAttribute(); 51 | 52 | if(attribute instanceof IterableAttribute ) { 53 | ((IterableAttribute) attribute).setValue(dctmObject, (List) valueFromClass); 54 | } else { 55 | IDfValue value = new DfValue(valueFromClass,fieldType.getAttribute().getDfAttributeType()); 56 | dctmObject.setValue(fieldType.getAttribute().getName(), value); 57 | } 58 | 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/mapping/BasicDctmPersistentEntity.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.mapping; 2 | 3 | import org.springframework.data.mapping.model.BasicPersistentEntity; 4 | import org.springframework.data.util.TypeInformation; 5 | 6 | import java.util.Comparator; 7 | 8 | /** 9 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 10 | * EMC Confidential: Restricted Internal Distribution 11 | */ 12 | 13 | 14 | /** 15 | * 16 | * @param 17 | * 18 | * @author Raman Walia 19 | */ 20 | public class BasicDctmPersistentEntity extends BasicPersistentEntity 21 | 22 | { 23 | public BasicDctmPersistentEntity(TypeInformation information) { 24 | super(information); 25 | } 26 | 27 | public BasicDctmPersistentEntity(TypeInformation information, Comparator comparator) { 28 | super(information, comparator); 29 | } 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/mapping/BasicDctmPersistentProperty.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.mapping; 2 | 3 | import org.springframework.data.mapping.Association; 4 | import org.springframework.data.mapping.PersistentEntity; 5 | import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty; 6 | import org.springframework.data.mapping.model.SimpleTypeHolder; 7 | 8 | import java.beans.PropertyDescriptor; 9 | import java.lang.reflect.Field; 10 | 11 | /* 12 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 13 | * EMC Confidential: Restricted Internal Distribution 14 | * 15 | * @author Raman Walia 16 | */ 17 | 18 | public class BasicDctmPersistentProperty extends AnnotationBasedPersistentProperty 19 | implements DctmPersistentProperty{ 20 | 21 | /** 22 | * Creates a new {@link AnnotationBasedPersistentProperty}. 23 | * 24 | * @param field must not be {@literal null}. 25 | * @param propertyDescriptor can be {@literal null}. 26 | * @param owner must not be {@literal null}. 27 | * @param simpleTypeHolder 28 | */ 29 | public BasicDctmPersistentProperty(Field field, PropertyDescriptor propertyDescriptor, PersistentEntity owner, SimpleTypeHolder simpleTypeHolder) { 30 | super(field, propertyDescriptor, owner, simpleTypeHolder); 31 | } 32 | 33 | @Override 34 | protected Association createAssociation() { 35 | return new Association(this, null); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/mapping/DctmAttribute.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.mapping; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | 7 | /** 8 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 9 | * EMC Confidential: Restricted Internal Distribution 10 | */ 11 | 12 | /** 13 | *  * Annotation to define custom metadata for DCTMObject fields. 14 | * 15 | * @author Raman Walia 16 | *   17 | */ 18 | 19 | @Documented 20 | @Retention(RetentionPolicy.RUNTIME) 21 | public @interface DctmAttribute { 22 | 23 | /** 24 | * The key to be used to store the field inside the document. 25 | * 26 | * @return String 27 | */ 28 | 29 | String value() default ""; 30 | } 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/mapping/DctmEntity.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.mapping; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Inherited; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | import org.springframework.data.annotation.Persistent; 10 | 11 | /** 12 | *  * Identifies a domain object to be persisted to Documentum. 13 | *   14 | */ 15 | @Persistent 16 | @Inherited 17 | @Retention(RetentionPolicy.RUNTIME) 18 | @Target({ElementType.TYPE}) 19 | public @interface DctmEntity { 20 | 21 | String repository() default ""; 22 | 23 | /** 24 | * Defines the default language to be used with this document. 25 | */ 26 | String language() default ""; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/mapping/DctmMappingContext.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.mapping; 2 | 3 | import org.springframework.data.mapping.context.AbstractMappingContext; 4 | import org.springframework.data.mapping.model.SimpleTypeHolder; 5 | import org.springframework.data.util.TypeInformation; 6 | 7 | import java.beans.PropertyDescriptor; 8 | import java.lang.reflect.Field; 9 | 10 | /** 11 | * Created by waliar on 7/5/16. 12 | */ 13 | public class DctmMappingContext extends AbstractMappingContext, DctmPersistentProperty> { 14 | @Override 15 | protected BasicDctmPersistentEntity createPersistentEntity(TypeInformation typeInformation) { 16 | return new BasicDctmPersistentEntity(typeInformation); 17 | } 18 | 19 | @Override 20 | protected DctmPersistentProperty createPersistentProperty(Field field, PropertyDescriptor descriptor, 21 | BasicDctmPersistentEntity owner, 22 | SimpleTypeHolder simpleTypeHolder) { 23 | return new BasicDctmPersistentProperty(field,descriptor, owner, simpleTypeHolder); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/mapping/DctmPersistentProperty.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.mapping; 2 | 3 | import org.springframework.data.mapping.PersistentProperty; 4 | 5 | /** 6 | * Created by waliar on 7/5/16. 7 | */ 8 | public interface DctmPersistentProperty extends PersistentProperty { 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/mapping/MappingHandler.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.mapping; 2 | 3 | import java.lang.reflect.Field; 4 | import java.lang.reflect.ParameterizedType; 5 | import java.lang.reflect.Type; 6 | import java.util.ArrayList; 7 | import java.util.Arrays; 8 | import java.util.HashSet; 9 | import java.util.List; 10 | import java.util.Set; 11 | 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.data.annotation.Id; 14 | import org.springframework.stereotype.Component; 15 | import org.springframework.util.Assert; 16 | 17 | import com.documentum.fc.common.DfException; 18 | import com.emc.documentum.springdata.core.GenericCache; 19 | import com.emc.documentum.springdata.entitymanager.EntityTypeHandler; 20 | import com.emc.documentum.springdata.entitymanager.annotations.Content; 21 | import com.emc.documentum.springdata.entitymanager.annotations.Relation; 22 | import com.emc.documentum.springdata.entitymanager.annotations.RelationshipType; 23 | import com.emc.documentum.springdata.entitymanager.attributes.Attribute; 24 | import com.emc.documentum.springdata.entitymanager.attributes.AttributeFactory; 25 | import com.emc.documentum.springdata.entitymanager.attributes.AttributeType; 26 | import com.emc.documentum.springdata.entitymanager.attributes.TypeUtils; 27 | 28 | @Component 29 | public class MappingHandler { 30 | 31 | @Autowired 32 | private EntityTypeHandler typeHandler; 33 | private final GenericCache cache; 34 | private final GenericCache reverseCache;// TODO change name 35 | private final Set> initializingSet = new HashSet<>(); 36 | 37 | public MappingHandler() { 38 | cache = new GenericCache(); 39 | reverseCache = new GenericCache(); 40 | } 41 | 42 | public String getIdField(T objectOfEntityClass) throws DfException { 43 | return getIdField(objectOfEntityClass.getClass()); 44 | } 45 | 46 | public String getIdField(Class entityClass) throws DfException { 47 | Assert.notNull(entityClass, "No class parameter provided, entity collection can't be determined!"); 48 | if (cache.getEntry(entityClass) == null) { 49 | setAttributeMappingInCache(entityClass); 50 | } 51 | return getIDFromCache(entityClass); 52 | } 53 | 54 | @SuppressWarnings("unchecked") 55 | private String getIDFromCache(Class entityClass) { 56 | Assert.notNull(entityClass, "No class parameter provided, entity collection can't be determined!"); 57 | ArrayList mapping = (ArrayList)cache.getEntry(entityClass); 58 | 59 | for (AttributeType attributeType : mapping) { 60 | if (attributeType.getAttribute().getName().equals("r_object_id")) { 61 | return attributeType.getFieldName(); 62 | } 63 | } 64 | return null; 65 | } 66 | 67 | public ArrayList getAttributeMappings(T objectOfEntityClass) throws DfException { 68 | return getAttributeMappings(objectOfEntityClass.getClass()); 69 | } 70 | 71 | @SuppressWarnings("unchecked") 72 | public ArrayList getAttributeMappings(Class entityClass) throws DfException { 73 | Assert.notNull(entityClass, "No class parameter provided, entity collection can't be determined!"); 74 | 75 | return cache.getEntry(entityClass) == null ? setAttributeMappingInCache(entityClass) : (ArrayList)cache.getEntry(entityClass); 76 | } 77 | 78 | private ArrayList setAttributeMappingInCache(Class entityClass) throws DfException { 79 | 80 | initializingSet.add(entityClass); 81 | ArrayList mapping = new ArrayList<>(); 82 | Field[] fields = getFields(entityClass); 83 | 84 | for (Field field : fields) { 85 | field.setAccessible(true); 86 | 87 | if(!isContentAttribute(field)) { 88 | if (isRelation(field)) { 89 | if(!initializingSet.contains(getRelatedEntityClass(field))) { 90 | getAttributeMappings(getRelatedEntityClass(field)); 91 | } 92 | } 93 | addMapping(mapping, field); 94 | } 95 | } 96 | cache.setEntry(entityClass, mapping); 97 | reverseCache.setEntry(typeHandler.getEntityObjectName(entityClass), entityClass); 98 | initializingSet.remove(entityClass); 99 | return mapping; 100 | } 101 | 102 | public Class getEntityClass(String repositoryEntityName) { 103 | return (Class)reverseCache.getEntry(repositoryEntityName); 104 | } 105 | 106 | public Field[] getFields(Class entityClass) throws DfException { 107 | 108 | List fieldList = new ArrayList(); 109 | Class tmpClass = entityClass; 110 | while (tmpClass != null) { 111 | fieldList.addAll(Arrays.asList(tmpClass.getDeclaredFields())); 112 | tmpClass = tmpClass.getSuperclass(); 113 | } 114 | Field[] fields = new Field[fieldList.size()]; 115 | fields = fieldList.toArray(fields); 116 | 117 | if (fields.length == 0) { 118 | throw new DfException("No fields to map for the given class!"); 119 | } 120 | return fields; 121 | } 122 | 123 | private void addMapping(ArrayList mapping, Field f) { 124 | String attributeName = getEntityFieldName(f); 125 | Attribute attribute = AttributeFactory.getAttribute(f, attributeName); 126 | AttributeType attributeType = new AttributeType(f.getName(), attribute, isRelation(f), 127 | isRelation(f) ? f.getAnnotation(Relation.class).name() : "", getRelationshipType(f), 128 | getRelatedEntityClass(f)); 129 | 130 | mapping.add(attributeType); 131 | } 132 | 133 | private RelationshipType getRelationshipType(Field field) { 134 | return isRelation(field) ? field.getAnnotation(Relation.class).value() : null; 135 | } 136 | 137 | private Class getRelatedEntityClass(Field field) { 138 | if(!isRelation(field)) 139 | return null; 140 | 141 | Class fieldType = field.getType(); 142 | Type type = TypeUtils.isCollection(fieldType) ? ((ParameterizedType)field.getGenericType()).getActualTypeArguments()[0] : field.getGenericType(); 143 | return (Class)type; 144 | } 145 | 146 | private boolean isRelation(Field f) { 147 | return f.getAnnotation(Relation.class) != null; 148 | } 149 | 150 | private boolean isContentAttribute(Field f) { 151 | return f.getAnnotation(Content.class) != null; 152 | } 153 | 154 | private String getEntityFieldName(Field f) { 155 | DctmAttribute dctmAttribute; 156 | String attributeName; 157 | 158 | if (f.isAnnotationPresent(Id.class)) { 159 | attributeName = "r_object_id"; 160 | } else if (f.isAnnotationPresent(DctmAttribute.class)) { 161 | dctmAttribute = f.getAnnotation(DctmAttribute.class); 162 | attributeName = dctmAttribute == null ? f.getName() : dctmAttribute.value(); 163 | } else { 164 | attributeName = f.getName(); 165 | } 166 | return attributeName; 167 | } 168 | 169 | @SuppressWarnings("unchecked") 170 | public List getRelations(T objectToSave) throws DfException { 171 | ArrayList attributeMappings = getAttributeMappings(objectToSave); 172 | List relations = new ArrayList(); 173 | 174 | for (AttributeType attributeType : attributeMappings) { 175 | if(attributeType.isRelation()) { 176 | relations.add(attributeType); 177 | } 178 | } 179 | return relations; 180 | } 181 | } 182 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/entitymanager/mapping/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | /** 5 | * @author MacbookPro 6 | * 7 | */ 8 | package com.emc.documentum.springdata.entitymanager.mapping; -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/log/AutowiredLogger.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.log; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /* 9 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 10 | * EMC Confidential: Restricted Internal Distribution 11 | */ 12 | 13 | /* 14 | * Marker annotation to inject logger 15 | */ 16 | @Retention(RetentionPolicy.RUNTIME) 17 | @Target(ElementType.FIELD) 18 | public @interface AutowiredLogger { 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/log/LoggerInjector.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.log; 2 | 3 | /* 4 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 5 | * EMC Confidential: Restricted Internal Distribution 6 | */ 7 | 8 | import java.lang.reflect.Field; 9 | 10 | import org.apache.log4j.Logger; 11 | import org.springframework.beans.BeansException; 12 | import org.springframework.beans.factory.config.BeanPostProcessor; 13 | import org.springframework.stereotype.Component; 14 | import org.springframework.util.ReflectionUtils; 15 | 16 | @Component 17 | public class LoggerInjector implements BeanPostProcessor { 18 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { 19 | return bean; 20 | } 21 | 22 | public Object postProcessBeforeInitialization(final Object bean, String beanName) throws BeansException { 23 | 24 | ReflectionUtils.FieldCallback fieldCallback = new ReflectionUtils.FieldCallback() { 25 | 26 | public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException { 27 | ReflectionUtils.makeAccessible(field); 28 | if (field.getAnnotation(AutowiredLogger.class) != null && field.getDeclaringClass().equals(Logger.class)) { 29 | field.set(bean, Logger.getLogger(bean.getClass())); 30 | } 31 | } 32 | }; 33 | 34 | ReflectionUtils.doWithFields(bean.getClass(), fieldCallback); 35 | return bean; 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/DctmRepository.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.springframework.data.repository.CrudRepository; 6 | import org.springframework.data.repository.NoRepositoryBean; 7 | 8 | /* 9 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 10 | * EMC Confidential: Restricted Internal Distribution 11 | */ 12 | 13 | @NoRepositoryBean 14 | public interface DctmRepository extends CrudRepository { 15 | 16 | S save(S entity); 17 | 18 | Iterable save(Iterable entities); 19 | 20 | T findOne(ID id); 21 | 22 | boolean exists(ID id); 23 | 24 | Iterable findAll(); 25 | 26 | Iterable findAll(Iterable ids); 27 | 28 | long count(); 29 | 30 | void delete(ID id); 31 | 32 | void delete(T entity); 33 | 34 | void delete(Iterable entities); 35 | 36 | void deleteAll(); 37 | 38 | //TODO void update(T entity); 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/DctmRepositoryWithContent.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.springframework.data.repository.NoRepositoryBean; 6 | 7 | /* 8 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 9 | * EMC Confidential: Restricted Internal Distribution 10 | */ 11 | @NoRepositoryBean 12 | public interface DctmRepositoryWithContent extends DctmRepository { 13 | void setContent(T object, String contentType, String path); 14 | 15 | String getContent(T object, String path); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/Query.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | import org.springframework.data.annotation.QueryAnnotation; 10 | 11 | /* 12 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 13 | * EMC Confidential: Restricted Internal Distribution 14 | */ 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @Target(ElementType.METHOD) 17 | //@Documented 18 | @QueryAnnotation 19 | public @interface Query { 20 | 21 | String value() default ""; 22 | 23 | String countQuery() default ""; 24 | } -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/config/AbstractDctmConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.config; 2 | 3 | import org.springframework.context.annotation.ComponentScan; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | /* 7 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 8 | * EMC Confidential: Restricted Internal Distribution 9 | */ 10 | @Configuration 11 | @EnableDctmRepositories 12 | @ComponentScan(basePackages = {"com.emc.documentum.springdata"})//TODO: Make this a little more concise 13 | public abstract class AbstractDctmConfiguration { 14 | //Add the conversion service 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/config/DctmAttribute.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.config; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /* 9 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 10 | * EMC Confidential: Restricted Internal Distribution 11 | */ 12 | //TODO: Consider this on methods (setters). Although, setting the target to method will make it too generic to make the intent clear. 13 | @Target(ElementType.FIELD) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | public @interface DctmAttribute { 16 | String name(); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/config/DctmRepositoriesRegistrar.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.config; 2 | 3 | import java.lang.annotation.Annotation; 4 | 5 | import org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport; 6 | import org.springframework.data.repository.config.RepositoryConfigurationExtension; 7 | 8 | /* 9 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 10 | * EMC Confidential: Restricted Internal Distribution 11 | */ 12 | public class DctmRepositoriesRegistrar extends RepositoryBeanDefinitionRegistrarSupport { 13 | 14 | @Override 15 | protected Class getAnnotation() { 16 | return EnableDctmRepositories.class; 17 | } 18 | 19 | @Override 20 | protected RepositoryConfigurationExtension getExtension() { 21 | return new DctmRepositoryConfigExtension(); 22 | } 23 | } -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/config/DctmRepositoryConfigExtension.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.config; 2 | 3 | import java.util.Locale; 4 | 5 | import org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport; 6 | 7 | import com.emc.documentum.springdata.repository.support.DctmRepositoryFactoryBean; 8 | 9 | /* 10 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 11 | * EMC Confidential: Restricted Internal Distribution 12 | */ 13 | public class DctmRepositoryConfigExtension extends RepositoryConfigurationExtensionSupport { 14 | 15 | @Override 16 | public String getModuleName() { 17 | return "DCTM"; 18 | } 19 | 20 | @Override 21 | public String getRepositoryFactoryClassName() { 22 | return DctmRepositoryFactoryBean.class.getName(); 23 | } 24 | 25 | @Override 26 | protected String getModulePrefix() { 27 | return getModuleName().toLowerCase(Locale.US); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/config/EnableDctmRepositories.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.config; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Inherited; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | import org.springframework.context.annotation.ComponentScan.Filter; 10 | import org.springframework.context.annotation.Import; 11 | import org.springframework.data.repository.query.QueryLookupStrategy.Key; 12 | 13 | import com.emc.documentum.springdata.repository.support.DctmRepositoryFactoryBean; 14 | 15 | /* 16 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 17 | * EMC Confidential: Restricted Internal Distribution 18 | */ 19 | @Inherited 20 | @Target(ElementType.TYPE) 21 | @Retention(RetentionPolicy.RUNTIME) 22 | @Import(DctmRepositoriesRegistrar.class) 23 | public @interface EnableDctmRepositories { 24 | 25 | String[] value() default {}; 26 | 27 | String[] basePackages() default {}; 28 | 29 | Class[] basePackageClasses() default {}; 30 | 31 | Filter[] includeFilters() default {}; 32 | 33 | Filter[] excludeFilters() default {}; 34 | 35 | String repositoryImplementationPostfix() default "Impl"; 36 | 37 | String namedQueriesLocation() default ""; 38 | 39 | Key queryLookupStrategy() default Key.CREATE_IF_NOT_FOUND; 40 | 41 | Class repositoryFactoryBeanClass() default DctmRepositoryFactoryBean.class; 42 | 43 | // String entityManagerFactoryRef() default "entityManagerFactory"; 44 | 45 | // String transactionManagerRef() default "transactionManager"; 46 | 47 | boolean considerNestedRepositories() default false; 48 | 49 | boolean enableDefaultTransactions() default false; 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/query/AbstractDctmQuery.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.query; 2 | 3 | import org.springframework.data.repository.query.RepositoryQuery; 4 | 5 | import com.emc.documentum.springdata.core.DctmOperations; 6 | import com.emc.documentum.springdata.repository.query.execution.CollectionExecution; 7 | import com.emc.documentum.springdata.repository.query.execution.Execution; 8 | import com.emc.documentum.springdata.repository.query.execution.ModifyingQuery; 9 | import com.emc.documentum.springdata.repository.query.execution.SingleEntityExecution; 10 | 11 | /* 12 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 13 | * EMC Confidential: Restricted Internal Distribution 14 | */ 15 | public abstract class AbstractDctmQuery implements RepositoryQuery { 16 | 17 | protected final DctmOperations dctmOperations; 18 | protected final DctmQueryMethod queryMethod; 19 | 20 | public AbstractDctmQuery(DctmOperations dctmOperations, DctmQueryMethod queryMethod) { 21 | this.dctmOperations = dctmOperations; 22 | this.queryMethod = queryMethod; 23 | } 24 | 25 | @Override 26 | public Object execute(Object[] parameters) { 27 | Execution execution = getExecution(); 28 | DctmQuery query = createQuery(parameters); 29 | return execution.execute(query, dctmOperations, queryMethod.getEntityInformation().getJavaType()); 30 | } 31 | 32 | protected abstract DctmQuery createQuery(Object[] parameters); 33 | 34 | private Execution getExecution() { 35 | if(queryMethod.isCollectionQuery()) { 36 | return new CollectionExecution(); 37 | } else if(queryMethod.isModifyingQuery()) { 38 | return new ModifyingQuery(); 39 | } else { 40 | return new SingleEntityExecution(); 41 | } 42 | } 43 | 44 | @Override 45 | public DctmQueryMethod getQueryMethod() { 46 | return queryMethod; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/query/DctmEntityMetadata.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.query; 2 | 3 | import org.springframework.data.repository.core.EntityMetadata; 4 | 5 | /* 6 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 7 | * EMC Confidential: Restricted Internal Distribution 8 | */ 9 | public interface DctmEntityMetadata extends EntityMetadata { 10 | //TODO: Will be used with query DSL 11 | String getDctmEntityName(); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/query/DctmQuery.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.query; 2 | 3 | import org.springframework.data.domain.Sort; 4 | 5 | import com.mysema.query.types.Predicate; 6 | 7 | /* 8 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 9 | * EMC Confidential: Restricted Internal Distribution 10 | */ 11 | public class DctmQuery { 12 | 13 | private final Predicate predicate; 14 | private final String queryString; 15 | private final boolean isCompleteQuery; 16 | 17 | public DctmQuery(String queryString) { 18 | this(queryString, null, true); 19 | } 20 | 21 | public DctmQuery(Predicate predicate) { 22 | this(null, predicate, false); 23 | } 24 | 25 | private DctmQuery(String queryString, Predicate predicate, boolean isCompleteQuery) { 26 | this.queryString = queryString; 27 | this.predicate = predicate; 28 | this.isCompleteQuery = isCompleteQuery; 29 | } 30 | 31 | public DctmQuery with(Sort sort) { 32 | //TODO Implement query modifiers for sort 33 | return this; 34 | } 35 | 36 | public String getPredicate() { 37 | //TODO: There has got to be a better way to do this, I should ask the mysema guys. 38 | return predicate.toString().replaceAll("\\|\\|", "OR").replaceAll("\\&\\&", "AND"); 39 | } 40 | 41 | public boolean isCompleteQuery() { 42 | return isCompleteQuery; 43 | } 44 | 45 | public String getQueryString() { 46 | return queryString; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/query/DctmQueryCreator.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.query; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Iterator; 5 | 6 | import org.springframework.data.domain.Sort; 7 | import org.springframework.data.mapping.PropertyPath; 8 | import org.springframework.data.repository.query.ParameterAccessor; 9 | import org.springframework.data.repository.query.parser.AbstractQueryCreator; 10 | import org.springframework.data.repository.query.parser.Part; 11 | import org.springframework.data.repository.query.parser.PartTree; 12 | import org.springframework.util.Assert; 13 | 14 | import com.documentum.fc.common.DfException; 15 | import com.emc.documentum.springdata.entitymanager.attributes.AttributeType; 16 | import com.emc.documentum.springdata.entitymanager.mapping.MappingHandler; 17 | import com.mysema.query.BooleanBuilder; 18 | import com.mysema.query.types.ConstantImpl; 19 | import com.mysema.query.types.Predicate; 20 | import com.mysema.query.types.expr.BooleanOperation; 21 | import com.mysema.query.types.path.PathBuilder; 22 | 23 | /* 24 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 25 | * EMC Confidential: Restricted Internal Distribution 26 | */ 27 | public class DctmQueryCreator extends AbstractQueryCreator { 28 | 29 | private final PathBuilder pathBuilder; 30 | private final MappingHandler mappingHandler; 31 | private DctmQueryMethod queryMethod; 32 | 33 | @SuppressWarnings("unchecked") 34 | public DctmQueryCreator(MappingHandler mappingHandler, PartTree tree, DctmQueryMethod queryMethod, ParameterAccessor accessor) { 35 | super(tree, accessor); 36 | this.mappingHandler = mappingHandler; 37 | this.queryMethod = queryMethod; 38 | pathBuilder = new PathBuilder(queryMethod.getEntityInformation().getJavaType(), queryMethod.getEntityInformation().getDctmEntityName()); 39 | } 40 | 41 | @SuppressWarnings("unchecked") 42 | @Override 43 | protected Predicate create(Part part, Iterator iterator) { 44 | Object value = iterator.next(); 45 | 46 | try { 47 | switch (part.getType()) { 48 | case SIMPLE_PROPERTY: 49 | if (part.getProperty().getType() == String.class) { 50 | value = escape((String)value); 51 | } 52 | return pathBuilder.get(getDctmAttributeName(part), part.getProperty().getType()).eq(value); 53 | 54 | case GREATER_THAN: 55 | return pathBuilder.getNumber(getDctmAttributeName(part), part.getProperty().getType()).gt(new ConstantImpl<>((Number)value)); 56 | 57 | default: 58 | throw new UnsupportedOperationException(String.format("Unidentifiable part of the query {%s}", part.getType().name())); 59 | } 60 | } catch (DfException e) { 61 | e.printStackTrace(); 62 | return null; 63 | } 64 | } 65 | 66 | private String getDctmAttributeName(Part part) throws DfException { 67 | ArrayList attributeMappings = mappingHandler.getAttributeMappings(queryMethod.getEntityInformation().getJavaType()); 68 | PropertyPath property = part.getProperty(); 69 | for (AttributeType attributeMapping : attributeMappings) { 70 | if (attributeMapping.getFieldName().equalsIgnoreCase(property.getSegment())) { 71 | return attributeMapping.getAttribute().getName(); 72 | } 73 | } 74 | return null; 75 | } 76 | 77 | private String escape(String property) { 78 | return "'" + property + "'"; 79 | } 80 | 81 | @Override 82 | protected Predicate and(Part part, Predicate base, Iterator iterator) { 83 | if(base == null) 84 | return create(part, iterator); 85 | 86 | Predicate right = create(part, iterator); 87 | return ((BooleanOperation)base).and(right); 88 | } 89 | 90 | @Override 91 | protected Predicate or(Predicate base, Predicate criteria) { 92 | Assert.notNull(base); 93 | Assert.notNull(criteria); 94 | BooleanBuilder or = new BooleanBuilder(base).or(criteria); 95 | return or.getValue(); 96 | } 97 | 98 | @Override 99 | protected DctmQuery complete(Predicate criteria, Sort sort) { 100 | DctmQuery dctmQuery = new DctmQuery(criteria); 101 | return dctmQuery.with(sort); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/query/DctmQueryMethod.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.query; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | import com.emc.documentum.springdata.repository.Query; 6 | import org.springframework.data.repository.core.EntityMetadata; 7 | import org.springframework.data.repository.core.RepositoryMetadata; 8 | import org.springframework.data.repository.query.QueryMethod; 9 | 10 | import com.emc.documentum.springdata.repository.support.SimpleDctmEntityInformation; 11 | 12 | /* 13 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 14 | * EMC Confidential: Restricted Internal Distribution 15 | */ 16 | public class DctmQueryMethod extends QueryMethod { 17 | 18 | private final DctmEntityMetadata dctmEntityMetadata; 19 | private final Method method; 20 | 21 | /** 22 | * Creates a new {@link QueryMethod} from the given parameters. Looks up the correct query to use for following 23 | * invocations of the method given. 24 | * 25 | * @param method must not be {@literal null} 26 | * @param metadata must not be {@literal null} 27 | */ 28 | @SuppressWarnings("unchecked") 29 | public DctmQueryMethod(Method method, RepositoryMetadata metadata) { 30 | super(method, metadata); 31 | this.method = method; 32 | dctmEntityMetadata = new SimpleDctmEntityInformation(metadata.getDomainType()); 33 | } 34 | 35 | @Override 36 | public DctmEntityMetadata getEntityInformation() { 37 | return dctmEntityMetadata; 38 | } 39 | 40 | public String getQuery() { 41 | return method.getAnnotation(Query.class).value(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/query/PartTreeDctmQuery.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.query; 2 | 3 | import javax.management.Query; 4 | 5 | import org.springframework.data.repository.query.ParameterAccessor; 6 | import org.springframework.data.repository.query.ParametersParameterAccessor; 7 | import org.springframework.data.repository.query.QueryMethod; 8 | import org.springframework.data.repository.query.parser.PartTree; 9 | 10 | import com.emc.documentum.springdata.core.DctmOperations; 11 | import com.emc.documentum.springdata.entitymanager.mapping.MappingHandler; 12 | 13 | /* 14 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 15 | * EMC Confidential: Restricted Internal Distribution 16 | */ 17 | public class PartTreeDctmQuery extends AbstractDctmQuery { 18 | 19 | private final PartTree partTree; 20 | private final MappingHandler mappingHandler; 21 | 22 | public PartTreeDctmQuery(MappingHandler mappingHandler, DctmOperations dctmOperations, DctmQueryMethod queryMethod) { 23 | super(dctmOperations, queryMethod); 24 | this.mappingHandler = mappingHandler; 25 | String queryMethodName = queryMethod.getName(); 26 | if(queryMethodName.equalsIgnoreCase("setContent") || queryMethodName.equalsIgnoreCase("getContent")) { 27 | queryMethodName = "content"; 28 | } 29 | partTree = new PartTree(queryMethodName, queryMethod.getEntityInformation().getJavaType()); 30 | } 31 | 32 | public DctmQuery createQuery(Object[] parameters) { 33 | DctmQueryCreator queryCreator = new DctmQueryCreator(mappingHandler, partTree, getQueryMethod(), new ParametersParameterAccessor( 34 | getQueryMethod().getParameters(), parameters)); 35 | 36 | return queryCreator.createQuery(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/query/SimpleDctmEntityMetadata.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.query; 2 | 3 | /* 4 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 5 | * EMC Confidential: Restricted Internal Distribution 6 | */ 7 | public class SimpleDctmEntityMetadata{ 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/query/StringBasedDctmQuery.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.query; 2 | 3 | import javax.management.Query; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.context.annotation.Lazy; 7 | import org.springframework.context.annotation.Scope; 8 | import org.springframework.data.repository.core.RepositoryMetadata; 9 | import org.springframework.data.repository.query.QueryMethod; 10 | import org.springframework.stereotype.Component; 11 | 12 | import com.emc.documentum.springdata.core.DctmOperations; 13 | 14 | /* 15 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 16 | * EMC Confidential: Restricted Internal Distribution 17 | */ 18 | 19 | /** 20 | * Used when the Query annotation is present 21 | */ 22 | @Component() 23 | @Scope("prototype") 24 | @Lazy 25 | public class StringBasedDctmQuery extends AbstractDctmQuery { 26 | 27 | @Autowired 28 | public StringBasedDctmQuery(DctmOperations dctmOperations, DctmQueryMethod queryMethod) { 29 | super(dctmOperations, queryMethod); 30 | } 31 | 32 | @Override 33 | protected DctmQuery createQuery(Object[] parameters) { 34 | String formedQuery = String.format(queryMethod.getQuery(), parameters); 35 | return new DctmQuery(formedQuery); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/query/execution/CollectionExecution.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.query.execution; 2 | 3 | import com.documentum.fc.common.DfException; 4 | import com.emc.documentum.springdata.core.DctmOperations; 5 | import com.emc.documentum.springdata.repository.query.DctmQuery; 6 | 7 | /* 8 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 9 | * EMC Confidential: Restricted Internal Distribution 10 | */ 11 | public class CollectionExecution implements Execution{ 12 | @Override 13 | public Object execute(DctmQuery query, DctmOperations dctmOperations, Class entityClass) { 14 | try { 15 | return dctmOperations.find(query, entityClass); 16 | } catch (DfException e) { 17 | e.printStackTrace(); 18 | } 19 | return null; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/query/execution/Execution.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.query.execution; 2 | 3 | import com.emc.documentum.springdata.core.DctmOperations; 4 | import com.emc.documentum.springdata.repository.query.AbstractDctmQuery; 5 | import com.emc.documentum.springdata.repository.query.DctmQuery; 6 | 7 | /* 8 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 9 | * EMC Confidential: Restricted Internal Distribution 10 | */ 11 | public interface Execution { 12 | 13 | Object execute(DctmQuery query, DctmOperations dctmOperations, Class entityClass); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/query/execution/ModifyingQuery.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.query.execution; 2 | 3 | import com.emc.documentum.springdata.core.DctmOperations; 4 | import com.emc.documentum.springdata.repository.query.DctmQuery; 5 | 6 | /* 7 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 8 | * EMC Confidential: Restricted Internal Distribution 9 | */ 10 | public class ModifyingQuery implements Execution { 11 | @Override 12 | public Object execute(DctmQuery query, DctmOperations dctmOperations, Class entityClass) { 13 | return null; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/query/execution/SingleEntityExecution.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.query.execution; 2 | 3 | import com.emc.documentum.springdata.core.DctmOperations; 4 | import com.emc.documentum.springdata.repository.query.DctmQuery; 5 | 6 | /* 7 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 8 | * EMC Confidential: Restricted Internal Distribution 9 | */ 10 | public class SingleEntityExecution implements Execution { 11 | @Override 12 | public Object execute(DctmQuery query, DctmOperations dctmOperations, Class entityClass) { 13 | return null; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/support/DctmAnnotationProcessor.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.support; 2 | 3 | import java.util.Collections; 4 | 5 | import javax.annotation.processing.RoundEnvironment; 6 | import javax.annotation.processing.SupportedAnnotationTypes; 7 | import javax.annotation.processing.SupportedSourceVersion; 8 | import javax.lang.model.SourceVersion; 9 | import javax.tools.Diagnostic; 10 | 11 | import com.emc.documentum.springdata.entitymanager.mapping.DctmEntity; 12 | import com.mysema.query.annotations.QueryEmbeddable; 13 | import com.mysema.query.annotations.QueryEmbedded; 14 | import com.mysema.query.annotations.QueryEntities; 15 | import com.mysema.query.annotations.QuerySupertype; 16 | import com.mysema.query.annotations.QueryTransient; 17 | import com.mysema.query.apt.AbstractQuerydslProcessor; 18 | import com.mysema.query.apt.Configuration; 19 | import com.mysema.query.apt.DefaultConfiguration; 20 | 21 | /* 22 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 23 | * EMC Confidential: Restricted Internal Distribution 24 | */ 25 | @SupportedAnnotationTypes({"com.emc.documentum.springdata.entitymanager.mapping.*", "com.mysema.query.annotations.*"}) 26 | @SupportedSourceVersion(SourceVersion.RELEASE_7) 27 | public class DctmAnnotationProcessor extends AbstractQuerydslProcessor { 28 | @Override 29 | protected Configuration createConfiguration(RoundEnvironment roundEnvironment) { 30 | processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Running " + getClass().getSimpleName()); 31 | DefaultConfiguration configuration = new DefaultConfiguration(roundEnvironment, processingEnv.getOptions(), Collections. emptySet(), 32 | QueryEntities.class, DctmEntity.class, QuerySupertype.class, 33 | QueryEmbeddable.class, QueryEmbedded.class, QueryTransient.class); 34 | configuration.setUnknownAsEmbedded(true); 35 | return configuration; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/support/DctmContentQuery.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.support; 2 | 3 | import org.springframework.data.repository.query.QueryMethod; 4 | import org.springframework.data.repository.query.RepositoryQuery; 5 | 6 | import com.documentum.fc.common.DfException; 7 | import com.emc.documentum.springdata.core.DctmOperations; 8 | import com.emc.documentum.springdata.repository.query.DctmQueryMethod; 9 | 10 | /* 11 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 12 | * EMC Confidential: Restricted Internal Distribution 13 | */ 14 | public class DctmContentQuery implements RepositoryQuery { 15 | 16 | private final DctmOperations dctmOperations; 17 | private final DctmQueryMethod queryMethod; 18 | ContentQueryType contentQueryType; 19 | 20 | public DctmContentQuery(DctmOperations dctmOperations, DctmQueryMethod queryMethod) { 21 | this.dctmOperations = dctmOperations; 22 | this.queryMethod = queryMethod; 23 | 24 | if(queryMethod.getName().equalsIgnoreCase("setcontent")) { 25 | contentQueryType = ContentQueryType.SET; 26 | } else if(queryMethod.getName().equalsIgnoreCase("getcontent")) { 27 | contentQueryType = ContentQueryType.GET; 28 | } else { 29 | throw new IllegalStateException(); 30 | } 31 | } 32 | 33 | //TODO: Smelly code 34 | @Override 35 | public Object execute(Object[] parameters) { 36 | try { 37 | switch(contentQueryType) { 38 | case GET: 39 | return dctmOperations.getContent(parameters[0], (String)parameters[1]); 40 | 41 | case SET: 42 | dctmOperations.setContent(parameters[0], (String)parameters[1], (String)parameters[2]); 43 | return "SAVED"; 44 | 45 | default: 46 | throw new UnsupportedOperationException("Cannot possibly execute this query"); 47 | } 48 | } catch (DfException e) { 49 | e.printStackTrace(); 50 | return null; 51 | } 52 | } 53 | 54 | @Override 55 | public QueryMethod getQueryMethod() { 56 | return queryMethod; 57 | } 58 | 59 | private enum ContentQueryType {GET, SET} 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/support/DctmEntityInformation.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.support; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.springframework.data.repository.core.EntityInformation; 6 | 7 | import com.emc.documentum.springdata.repository.query.DctmEntityMetadata; 8 | 9 | /* 10 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 11 | * EMC Confidential: Restricted Internal Distribution 12 | */ 13 | public interface DctmEntityInformation extends EntityInformation, DctmEntityMetadata { 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/support/DctmQueryLookupStrategy.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.support; 2 | 3 | import java.io.Serializable; 4 | import java.lang.reflect.Method; 5 | 6 | import org.apache.log4j.Logger; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.context.ApplicationContext; 9 | import org.springframework.data.repository.core.NamedQueries; 10 | import org.springframework.data.repository.core.RepositoryMetadata; 11 | import org.springframework.data.repository.query.QueryLookupStrategy; 12 | import org.springframework.data.repository.query.QueryMethod; 13 | import org.springframework.data.repository.query.RepositoryQuery; 14 | import org.springframework.stereotype.Component; 15 | import org.springframework.util.Assert; 16 | 17 | import com.emc.documentum.springdata.core.DctmOperations; 18 | import com.emc.documentum.springdata.entitymanager.mapping.MappingHandler; 19 | import com.emc.documentum.springdata.repository.DctmRepositoryWithContent; 20 | import com.emc.documentum.springdata.repository.Query; 21 | import com.emc.documentum.springdata.repository.query.DctmQueryMethod; 22 | import com.emc.documentum.springdata.repository.query.PartTreeDctmQuery; 23 | import com.emc.documentum.springdata.repository.query.StringBasedDctmQuery; 24 | 25 | /* 26 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 27 | * EMC Confidential: Restricted Internal Distribution 28 | */ 29 | @Component 30 | public class DctmQueryLookupStrategy implements QueryLookupStrategy { 31 | @Autowired 32 | ApplicationContext applicationContext; 33 | 34 | Logger logger = Logger.getLogger(DctmQueryLookupStrategy.class); 35 | 36 | @Override 37 | public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, NamedQueries namedQueries) { 38 | DctmQueryMethod queryMethod = new DctmQueryMethod(method, metadata); 39 | 40 | DctmOperations dctmOperations = applicationContext.getBean(DctmOperations.class); 41 | 42 | 43 | if(DctmRepositoryWithContent.class.isAssignableFrom(metadata.getRepositoryInterface())) { 44 | if(isContentMethod(method)) { 45 | return new DctmContentQuery(dctmOperations, queryMethod); 46 | } 47 | } 48 | 49 | return method.getAnnotation(Query.class) == null ? new PartTreeDctmQuery(applicationContext.getBean(MappingHandler.class), dctmOperations, 50 | queryMethod) : 51 | new StringBasedDctmQuery(dctmOperations, queryMethod); 52 | } 53 | 54 | private boolean isContentMethod(Method method) { 55 | //TODO Refine this with annotations!!! 56 | return method.getName().equalsIgnoreCase("setcontent") || method.getName().equalsIgnoreCase("getcontent"); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/support/DctmRepositoryFactory.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.support; 2 | 3 | import static org.springframework.data.querydsl.QueryDslUtils.QUERY_DSL_PRESENT; 4 | 5 | import java.io.Serializable; 6 | 7 | import org.springframework.context.ApplicationContext; 8 | import org.springframework.data.querydsl.QueryDslPredicateExecutor; 9 | import org.springframework.data.repository.core.RepositoryMetadata; 10 | import org.springframework.data.repository.core.support.RepositoryFactorySupport; 11 | import org.springframework.data.repository.query.EvaluationContextProvider; 12 | import org.springframework.data.repository.query.QueryLookupStrategy; 13 | 14 | import com.emc.documentum.springdata.repository.DctmRepository; 15 | import com.emc.documentum.springdata.repository.DctmRepositoryWithContent; 16 | 17 | /* 18 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 19 | * EMC Confidential: Restricted Internal Distribution 20 | */ 21 | public class DctmRepositoryFactory extends RepositoryFactorySupport { 22 | 23 | private final ApplicationContext applicationContext; 24 | 25 | public DctmRepositoryFactory(ApplicationContext applicationContext) { 26 | this.applicationContext = applicationContext; 27 | 28 | } 29 | 30 | @Override 31 | public DctmEntityInformation getEntityInformation(Class domainClass) { 32 | return new SimpleDctmEntityInformation<>(domainClass); 33 | } 34 | 35 | @SuppressWarnings("unchecked") 36 | @Override 37 | protected Object getTargetRepository(RepositoryMetadata metadata) { 38 | DctmEntityInformation dctmEntityInformation = getEntityInformation(metadata.getDomainType()); 39 | 40 | return getDctmRepository(metadata, dctmEntityInformation); 41 | } 42 | 43 | @SuppressWarnings("unchecked") 44 | private Object getDctmRepository(RepositoryMetadata metadata, DctmEntityInformation dctmEntityInformation) { 45 | Class repositoryInterface = metadata.getRepositoryInterface(); 46 | 47 | if(isQueryDslRepository(repositoryInterface)) { 48 | return DctmRepositoryWithContent.class.isAssignableFrom(repositoryInterface) ? 49 | new QueryDslDctmRepositoryWithContent<>(dctmEntityInformation, applicationContext) 50 | : new QueryDslDctmRepository<>(dctmEntityInformation, applicationContext); 51 | } 52 | else { 53 | return DctmRepositoryWithContent.class.isAssignableFrom(repositoryInterface) ? 54 | new SimpleDctmRepositoryWithContent<>(dctmEntityInformation, applicationContext) 55 | : new SimpleDctmRepository<>(dctmEntityInformation, applicationContext); 56 | } 57 | } 58 | 59 | @Override 60 | protected Class getRepositoryBaseClass(RepositoryMetadata metadata) { 61 | return isQueryDslRepository(metadata.getRepositoryInterface()) ? QueryDslDctmRepository.class : SimpleDctmRepository.class; 62 | } 63 | 64 | @Override 65 | protected QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key, EvaluationContextProvider evaluationContextProvider) { 66 | return applicationContext.getBean(DctmQueryLookupStrategy.class); 67 | } 68 | 69 | private static boolean isQueryDslRepository(Class repositoryInterface) { 70 | return QUERY_DSL_PRESENT && QueryDslPredicateExecutor.class.isAssignableFrom(repositoryInterface); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/support/DctmRepositoryFactoryBean.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.support; 2 | 3 | import com.emc.documentum.springdata.entitymanager.mapping.DctmMappingContext; 4 | import org.springframework.beans.BeansException; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.context.ApplicationContext; 7 | import org.springframework.context.ApplicationContextAware; 8 | import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport; 9 | import org.springframework.data.repository.core.support.RepositoryFactorySupport; 10 | 11 | /* 12 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 13 | * EMC Confidential: Restricted Internal Distribution 14 | */ 15 | //TODO: Do we start supporting transactions already? 16 | 17 | public class DctmRepositoryFactoryBean extends RepositoryFactoryBeanSupport implements ApplicationContextAware { 18 | 19 | ApplicationContext applicationContext; 20 | @Autowired 21 | DctmMappingContext mappingContext; 22 | 23 | @Override 24 | public void setApplicationContext(ApplicationContext appContext) throws BeansException { 25 | this.applicationContext = appContext; 26 | } 27 | 28 | @Override 29 | protected RepositoryFactorySupport createRepositoryFactory() { 30 | setMappingContext(mappingContext); 31 | return new DctmRepositoryFactory(applicationContext); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/support/QueryDslDctmRepository.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.support; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.springframework.context.ApplicationContext; 6 | import org.springframework.data.domain.Page; 7 | import org.springframework.data.domain.Pageable; 8 | import org.springframework.data.querydsl.QueryDslPredicateExecutor; 9 | import org.springframework.data.repository.NoRepositoryBean; 10 | 11 | import com.mysema.query.types.OrderSpecifier; 12 | import com.mysema.query.types.Predicate; 13 | 14 | /* 15 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 16 | * EMC Confidential: Restricted Internal Distribution 17 | */ 18 | @NoRepositoryBean 19 | public class QueryDslDctmRepository extends SimpleDctmRepository implements QueryDslPredicateExecutor { 20 | 21 | public QueryDslDctmRepository(DctmEntityInformation dctmEntity, ApplicationContext applicationContext) { 22 | super(dctmEntity, applicationContext); 23 | } 24 | 25 | @Override 26 | public T findOne(Predicate predicate) { 27 | return null; 28 | } 29 | 30 | @Override 31 | public Iterable findAll(Predicate predicate) { 32 | return null; 33 | } 34 | 35 | @Override 36 | public Iterable findAll(Predicate predicate, OrderSpecifier... orders) { 37 | return null; 38 | } 39 | 40 | @Override 41 | public Page findAll(Predicate predicate, Pageable pageable) { 42 | return null; 43 | } 44 | 45 | @Override 46 | public long count(Predicate predicate) { 47 | return 0; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/support/QueryDslDctmRepositoryWithContent.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.support; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.springframework.context.ApplicationContext; 6 | import org.springframework.data.domain.Page; 7 | import org.springframework.data.domain.Pageable; 8 | import org.springframework.data.querydsl.QueryDslPredicateExecutor; 9 | import org.springframework.data.repository.NoRepositoryBean; 10 | 11 | import com.emc.documentum.springdata.repository.DctmRepositoryWithContent; 12 | import com.mysema.query.types.OrderSpecifier; 13 | import com.mysema.query.types.Predicate; 14 | 15 | /* 16 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 17 | * EMC Confidential: Restricted Internal Distribution 18 | */ 19 | @NoRepositoryBean 20 | public class QueryDslDctmRepositoryWithContent extends SimpleDctmRepositoryWithContent 21 | implements QueryDslPredicateExecutor { 22 | 23 | public QueryDslDctmRepositoryWithContent(DctmEntityInformation dctmEntity, ApplicationContext applicationContext) { 24 | super(dctmEntity, applicationContext); 25 | } 26 | 27 | @Override 28 | public T findOne(Predicate predicate) { 29 | return null; 30 | } 31 | 32 | @Override 33 | public Iterable findAll(Predicate predicate) { 34 | return null; 35 | } 36 | 37 | @Override 38 | public Iterable findAll(Predicate predicate, OrderSpecifier... orders) { 39 | return null; 40 | } 41 | 42 | @Override 43 | public Page findAll(Predicate predicate, Pageable pageable) { 44 | return null; 45 | } 46 | 47 | @Override 48 | public long count(Predicate predicate) { 49 | return 0; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/support/SimpleDctmEntityInformation.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.support; 2 | 3 | import java.io.Serializable; 4 | 5 | import com.emc.documentum.springdata.entitymanager.mapping.DctmEntity; 6 | 7 | /* 8 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 9 | * EMC Confidential: Restricted Internal Distribution 10 | */ 11 | public class SimpleDctmEntityInformation implements DctmEntityInformation { 12 | //TODO: Adding fields & implementations on need basis 13 | 14 | private Class javaType; 15 | 16 | public SimpleDctmEntityInformation(Class javaType) { 17 | this.javaType = javaType; 18 | } 19 | 20 | @Override 21 | public String getDctmEntityName() { 22 | return javaType.getAnnotation(DctmEntity.class).repository(); 23 | } 24 | 25 | @Override 26 | public boolean isNew(T entity) { 27 | return false; 28 | } 29 | 30 | @Override 31 | public ID getId(T entity) { 32 | return null; 33 | } 34 | 35 | @Override 36 | public Class getIdType() { 37 | return null; 38 | } 39 | 40 | @Override 41 | public Class getJavaType() { 42 | return javaType; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/support/SimpleDctmRepository.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.support; 2 | 3 | import java.io.Serializable; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import org.apache.log4j.Logger; 8 | import org.springframework.context.ApplicationContext; 9 | 10 | import com.documentum.fc.common.DfException; 11 | import com.emc.documentum.springdata.core.DctmOperations; 12 | import com.emc.documentum.springdata.repository.DctmRepository; 13 | 14 | /* 15 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 16 | * EMC Confidential: Restricted Internal Distribution 17 | */ 18 | public class SimpleDctmRepository implements DctmRepository { 19 | 20 | private Logger logger = Logger.getLogger(SimpleDctmRepository.class); 21 | protected DctmEntityInformation dctmEntityInformation; 22 | protected DctmOperations dctmTemplate; 23 | 24 | public SimpleDctmRepository(DctmEntityInformation dctmEntityInformation, ApplicationContext applicationContext) { 25 | dctmTemplate = applicationContext.getBean(DctmOperations.class); 26 | this.dctmEntityInformation = dctmEntityInformation; 27 | } 28 | 29 | @Override 30 | public S save(S entity) { 31 | S createdEntity = null; 32 | try { 33 | createdEntity = dctmTemplate.create(entity); 34 | } catch (DfException e) { 35 | e.printStackTrace(); 36 | } 37 | return createdEntity; 38 | } 39 | 40 | @Override 41 | public Iterable save(Iterable entities) { 42 | List retVal = new ArrayList<>(); 43 | for (S entity : entities) { 44 | retVal.add(save(entity)); 45 | } 46 | return retVal; 47 | } 48 | 49 | @Override 50 | public T findOne(ID id) { 51 | T retVal = null; 52 | try { 53 | retVal = dctmTemplate.findById(id.toString(), dctmEntityInformation.getJavaType()); 54 | } catch (DfException e) { 55 | e.printStackTrace(); 56 | } 57 | return retVal; 58 | } 59 | 60 | @Override 61 | public boolean exists(ID id) { 62 | return findOne(id) != null; 63 | } 64 | 65 | @Override 66 | public Iterable findAll() { 67 | List retVal = null; 68 | try { 69 | retVal = dctmTemplate.findAll(dctmEntityInformation.getJavaType()); 70 | } catch (DfException e) { 71 | e.printStackTrace(); 72 | } 73 | return retVal; 74 | } 75 | 76 | @Override 77 | public Iterable findAll(Iterable ids) { 78 | List foundObjects = new ArrayList<>(); 79 | for (ID id : ids) { 80 | T found = findOne(id); 81 | if(found != null) 82 | foundObjects.add(found); 83 | } 84 | return foundObjects; 85 | } 86 | 87 | @Override 88 | public long count() { 89 | try { 90 | return dctmTemplate.count(dctmEntityInformation.getJavaType()); 91 | } catch (DfException e) { 92 | e.printStackTrace(); 93 | return 0; 94 | } 95 | } 96 | 97 | @Override 98 | public void delete(ID id) { 99 | try { 100 | dctmTemplate.deleteById(id.toString()); 101 | } catch (DfException e) { 102 | e.printStackTrace(); 103 | } 104 | } 105 | 106 | @Override 107 | public void delete(T entity) { 108 | try { 109 | dctmTemplate.delete(entity); 110 | } catch (DfException e) { 111 | e.printStackTrace(); 112 | } 113 | } 114 | 115 | @Override 116 | public void delete(Iterable entities) { 117 | for (T entity : entities) { 118 | try { 119 | dctmTemplate.delete(entity); 120 | } catch (DfException e) { 121 | e.printStackTrace(); 122 | } 123 | } 124 | } 125 | 126 | @Override 127 | public void deleteAll() { 128 | throw new UnsupportedOperationException();//TODO Coming Soon.... 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/repository/support/SimpleDctmRepositoryWithContent.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.support; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.springframework.context.ApplicationContext; 6 | import org.springframework.data.repository.NoRepositoryBean; 7 | 8 | import com.documentum.fc.common.DfException; 9 | import com.emc.documentum.springdata.repository.DctmRepositoryWithContent; 10 | 11 | /* 12 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 13 | * EMC Confidential: Restricted Internal Distribution 14 | */ 15 | @NoRepositoryBean 16 | public class SimpleDctmRepositoryWithContent extends SimpleDctmRepository 17 | implements DctmRepositoryWithContent { 18 | 19 | public SimpleDctmRepositoryWithContent(DctmEntityInformation dctmEntity, ApplicationContext applicationContext) { 20 | super(dctmEntity, applicationContext); 21 | } 22 | 23 | @Override 24 | public void setContent(T object, String contentType, String path) { 25 | try { 26 | dctmTemplate.setContent(object, contentType, path); 27 | } catch (DfException e) { 28 | e.printStackTrace(); 29 | } 30 | } 31 | 32 | @Override 33 | public String getContent(T object, String path) { 34 | try { 35 | return dctmTemplate.getContent(object, path); 36 | } catch (DfException e) { 37 | e.printStackTrace(); 38 | } 39 | return null; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/security/DocumentumAuthenticationProvider.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.security; 2 | 3 | import com.documentum.fc.client.DfClient; 4 | import com.documentum.fc.client.IDfClient; 5 | import com.documentum.fc.client.IDfDocbaseMap; 6 | import com.documentum.fc.common.DfException; 7 | import com.documentum.fc.common.DfLoginInfo; 8 | import com.documentum.fc.common.IDfLoginInfo; 9 | import com.emc.documentum.springdata.core.Documentum; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.data.authentication.UserCredentials; 12 | import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException; 13 | import org.springframework.security.authentication.AuthenticationProvider; 14 | import org.springframework.security.authentication.InternalAuthenticationServiceException; 15 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 16 | import org.springframework.security.core.Authentication; 17 | import org.springframework.security.core.AuthenticationException; 18 | import org.springframework.security.core.GrantedAuthority; 19 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 20 | import org.springframework.security.core.context.SecurityContextHolder; 21 | import org.springframework.stereotype.Component; 22 | 23 | import java.io.IOException; 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | 27 | /** 28 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 29 | * EMC Confidential: Restricted Internal Distribution 30 | */ 31 | 32 | /** 33 | * @author Raman Walia 34 | */ 35 | 36 | @Component 37 | public class DocumentumAuthenticationProvider implements AuthenticationProvider { 38 | 39 | @Autowired 40 | Documentum documentum; 41 | 42 | /** 43 | * Authentication is hardwired to DCTM. However, this method can be overridden to 44 | * change the authentication to any custom authentication. 45 | * 46 | * @param authentication 47 | * @return 48 | * @throws AuthenticationException 49 | */ 50 | @Override 51 | public Authentication authenticate(Authentication authentication) throws AuthenticationException { 52 | 53 | 54 | 55 | try { 56 | String username = authentication.getName(); 57 | String docBase = getRepositoryName(username); 58 | String password = authentication.getCredentials().toString(); 59 | 60 | authenticate(username,password, docBase); 61 | documentum.setCredentials(new UserCredentials(username, password)); 62 | documentum.setDocBase(docBase); 63 | List grantedAuths = new ArrayList(); 64 | grantedAuths.add(new SimpleGrantedAuthority("ROLE_USER")); 65 | return new UsernamePasswordAuthenticationToken(username,password, grantedAuths); 66 | } catch (IOException e) { 67 | throw new InternalAuthenticationServiceException("Unable to Authenticate", e); 68 | } catch (DfException e) { 69 | throw new InternalAuthenticationServiceException("Unable to Authenticate", e); 70 | } 71 | 72 | } 73 | 74 | 75 | @Override 76 | public boolean supports(Class aClass) { 77 | 78 | return aClass.equals(UsernamePasswordAuthenticationToken.class) ; 79 | } 80 | 81 | private boolean authenticate(String username, String password, String docBase) throws IOException, DfException { 82 | IDfLoginInfo loginInfo = new DfLoginInfo(username, password); 83 | 84 | IDfClient client = new DfClient(); 85 | client.authenticate(docBase, loginInfo); 86 | return true; 87 | } 88 | 89 | 90 | private String getRepositoryName(String userName) throws DfException { 91 | if (userName.contains("@")) 92 | return userName.substring(userName.indexOf('@'), userName.length()); 93 | else{ 94 | return getRepositoriesFromDocBroker(); 95 | 96 | } 97 | } 98 | 99 | private String getRepositoriesFromDocBroker() throws DfException { 100 | IDfClient client = new DfClient(); 101 | IDfDocbaseMap docbases= client.getDocbaseMap(); 102 | if (docbases.getDocbaseCount() == 1) 103 | return docbases.getDocbaseName(0); 104 | else 105 | throw new AuthenticationCredentialsNotFoundException("Docborker has more than one repository. Either" + 106 | " specify the repo name in repository.property or append it with user like username@reponame"); 107 | 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/com/emc/documentum/springdata/security/SecurityConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.security; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.ComponentScan; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 7 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 8 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 9 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 10 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 11 | /** 12 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 13 | * EMC Confidential: Restricted Internal Distribution 14 | */ 15 | 16 | /** 17 | * @author Raman Walia 18 | */ 19 | @Configuration 20 | @EnableGlobalMethodSecurity 21 | @EnableWebSecurity 22 | @ComponentScan("com.emc.documentum.springdata.security.*") 23 | 24 | public class SecurityConfiguration extends WebSecurityConfigurerAdapter{ 25 | 26 | @Autowired 27 | DocumentumAuthenticationProvider dctmAuthProvider; 28 | 29 | /** 30 | * This section defines the user accounts which can be used for 31 | * authentication as well as the roles each user has. 32 | */ 33 | @Override 34 | public void configure(AuthenticationManagerBuilder auth) throws Exception { 35 | auth.authenticationProvider(dctmAuthProvider); 36 | } 37 | 38 | @Override 39 | protected void configure(HttpSecurity http) throws Exception { 40 | http 41 | .authorizeRequests().anyRequest().authenticated() 42 | .and() 43 | .httpBasic(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/ApplicationConfig.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | 5 | import com.emc.documentum.springdata.repository.config.AbstractDctmConfiguration; 6 | import com.emc.documentum.springdata.repository.config.EnableDctmRepositories; 7 | 8 | /* 9 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 10 | * EMC Confidential: Restricted Internal Distribution 11 | */ 12 | @Configuration 13 | @EnableDctmRepositories 14 | public class ApplicationConfig extends AbstractDctmConfiguration{ 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/LoanQueryDslDctmRepository.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.querydsl.QueryDslPredicateExecutor; 6 | 7 | import com.emc.documentum.springdata.core.Loan; 8 | import com.emc.documentum.springdata.repository.DctmRepositoryWithContent; 9 | 10 | /* 11 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 12 | * EMC Confidential: Restricted Internal Distribution 13 | */ 14 | public interface LoanQueryDslDctmRepository extends DctmRepositoryWithContent, QueryDslPredicateExecutor { 15 | List findByAmountGreaterThan(int amount); 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/LoanRepository.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata; 2 | 3 | import com.emc.documentum.springdata.core.Loan; 4 | import com.emc.documentum.springdata.repository.DctmRepositoryWithContent; 5 | 6 | /* 7 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 8 | * EMC Confidential: Restricted Internal Distribution 9 | */ 10 | public interface LoanRepository extends DctmRepositoryWithContent { 11 | } 12 | -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/Person.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata; 2 | 3 | import org.springframework.data.annotation.Id; 4 | import org.springframework.data.annotation.TypeAlias; 5 | 6 | import com.emc.documentum.springdata.entitymanager.mapping.DctmEntity; 7 | import com.emc.documentum.springdata.entitymanager.mapping.DctmAttribute; 8 | 9 | @DctmEntity(repository = "persons") 10 | @TypeAlias("person") 11 | public class Person { 12 | 13 | @Id 14 | public String _id; 15 | 16 | public void set_id(String _id) { 17 | this._id = _id; 18 | } 19 | 20 | @DctmAttribute("firstname") 21 | private String name; 22 | 23 | public Integer age; 24 | 25 | @DctmAttribute("sex") 26 | private String gender; 27 | 28 | public String getName() { 29 | return name; 30 | } 31 | 32 | public String get_id() { 33 | return _id; 34 | } 35 | 36 | public void setName(String name) { 37 | this.name = name; 38 | } 39 | 40 | public Integer getAge() { 41 | return age; 42 | } 43 | 44 | public void setAge(Integer age) { 45 | this.age = age; 46 | } 47 | 48 | public String getGender() { 49 | return gender; 50 | } 51 | 52 | public void setGender(String gender) { 53 | this.gender = gender; 54 | } 55 | 56 | public Person(String name, Integer age, String gender) { 57 | this.name = name; 58 | this.age = age; 59 | this.gender = gender; 60 | } 61 | 62 | public Person() {} 63 | 64 | @Override 65 | public String toString() { 66 | return "Person{" + 67 | "_id='" + _id + '\'' + 68 | ", name='" + name + '\'' + 69 | ", age=" + age + 70 | ", gender='" + gender + '\'' + 71 | '}'; 72 | } 73 | 74 | @Override 75 | public boolean equals(Object o) { 76 | if (this == o) { return true; } 77 | if (o == null || getClass() != o.getClass()) { return false; } 78 | 79 | Person person = (Person)o; 80 | 81 | if (name != null ? !name.equals(person.name) : person.name != null) { return false; } 82 | if (age != null ? !age.equals(person.age) : person.age != null) { return false; } 83 | return !(gender != null ? !gender.equals(person.gender) : person.gender != null); 84 | 85 | } 86 | 87 | @Override 88 | public int hashCode() { 89 | int result = name != null ? name.hashCode() : 0; 90 | result = 31 * result + (age != null ? age.hashCode() : 0); 91 | result = 31 * result + (gender != null ? gender.hashCode() : 0); 92 | return result; 93 | } 94 | } 95 | 96 | -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/PersonQueryDslRepository.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.querydsl.QueryDslPredicateExecutor; 6 | 7 | import com.emc.documentum.springdata.repository.DctmRepository; 8 | import com.emc.documentum.springdata.repository.Query; 9 | 10 | /* 11 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 12 | * EMC Confidential: Restricted Internal Distribution 13 | */ 14 | public interface PersonQueryDslRepository extends DctmRepository, QueryDslPredicateExecutor { 15 | 16 | List findByName(String name); 17 | 18 | List findByNameOrGender(String name, String gender); 19 | 20 | // public long countByName(String name); 21 | 22 | @Query("select * from persons where %s = \'%s\'") 23 | List findSomeone(String attribute, String value); 24 | 25 | @Query("select * from persons where firstname = \'%s\' or age = %s") 26 | List findByAgeOrName(String name, int value); 27 | 28 | @Query("select * from persons where %s = %s") 29 | List findSomeone(String attribute, int value); 30 | 31 | List findByNameAndAge(String name, int age); 32 | 33 | List findByAgeBetween(int begin, int end); 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/PersonRepository.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata; 2 | 3 | import com.emc.documentum.springdata.repository.DctmRepository; 4 | 5 | /* 6 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 7 | * EMC Confidential: Restricted Internal Distribution 8 | */ 9 | public interface PersonRepository extends DctmRepository { 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/core/Address.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.core; 2 | 3 | import com.emc.documentum.springdata.entitymanager.mapping.DctmAttribute; 4 | import com.emc.documentum.springdata.entitymanager.mapping.DctmEntity; 5 | import org.springframework.data.annotation.Id; 6 | import org.springframework.data.annotation.TypeAlias; 7 | 8 | /** 9 | * Created with IntelliJ IDEA. 10 | * User: ramanwalia 11 | * Date: 20/03/15 12 | * Time: 9:25 PM 13 | * To change this template use File | Settings | File Templates. 14 | */ 15 | @DctmEntity(repository="addresses") 16 | @TypeAlias("address") 17 | public class Address { 18 | 19 | 20 | @Id 21 | String id; 22 | int doorNo; 23 | String street; 24 | String city; 25 | @DctmAttribute("stat") 26 | String state; 27 | String country; 28 | 29 | 30 | public String getId() { 31 | return id; 32 | } 33 | 34 | public void setId(String id) { 35 | this.id = id; 36 | } 37 | 38 | public int getDoorNo() { 39 | return doorNo; 40 | } 41 | 42 | public void setDoorNo(int doorNo) { 43 | this.doorNo = doorNo; 44 | } 45 | 46 | public String getStreet() { 47 | return street; 48 | } 49 | 50 | public void setStreet(String street) { 51 | this.street = street; 52 | } 53 | 54 | public String getCity() { 55 | return city; 56 | } 57 | 58 | public void setCity(String city) { 59 | this.city = city; 60 | } 61 | 62 | public String getState() { 63 | return state; 64 | } 65 | 66 | public void setState(String state) { 67 | this.state = state; 68 | } 69 | 70 | public String getCountry() { 71 | return country; 72 | } 73 | 74 | public void setCountry(String country) { 75 | this.country = country; 76 | } 77 | 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/core/Loan.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.core; 2 | 3 | import org.springframework.data.annotation.Id; 4 | 5 | import com.emc.documentum.springdata.entitymanager.mapping.DctmEntity; 6 | 7 | /** 8 | * Created with IntelliJ IDEA. 9 | * User: ramanwalia 10 | * Date: 03/04/15 11 | * Time: 9:58 PM 12 | * To change this template use File | Settings | File Templates. 13 | */ 14 | @DctmEntity(repository = "loan") 15 | public class Loan { 16 | public Loan() {} 17 | 18 | public Loan(int amount){ 19 | this.amount = amount; 20 | } 21 | 22 | public String getLoanId() { 23 | return loanId; 24 | } 25 | 26 | public void setLoanId(String loanId) { 27 | this.loanId = loanId; 28 | } 29 | 30 | public int getAmount() { 31 | return amount; 32 | } 33 | 34 | public void setAmount(int amount) { 35 | this.amount = amount; 36 | } 37 | 38 | @Override 39 | public boolean equals(Object o) { 40 | if (this == o) { return true; } 41 | if (o == null || getClass() != o.getClass()) { return false; } 42 | 43 | Loan loan = (Loan)o; 44 | 45 | if (amount != loan.amount) { return false; } 46 | return !(loanId != null ? !loanId.equals(loan.loanId) : loan.loanId != null); 47 | 48 | } 49 | 50 | @Override 51 | public int hashCode() { 52 | int result = loanId != null ? loanId.hashCode() : 0; 53 | result = 31 * result + amount; 54 | return result; 55 | } 56 | 57 | @Override 58 | public String toString() { 59 | return "Loan{" + 60 | "loanId='" + loanId + '\'' + 61 | ", amount=" + amount + 62 | '}'; 63 | } 64 | 65 | @Id 66 | String loanId; 67 | int amount; 68 | } 69 | -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/core/Person.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.core; 2 | 3 | import com.emc.documentum.springdata.entitymanager.annotations.Relation; 4 | 5 | import org.springframework.beans.factory.annotation.Configurable; 6 | import org.springframework.data.annotation.Id; 7 | import org.springframework.data.annotation.TypeAlias; 8 | 9 | import com.emc.documentum.springdata.entitymanager.annotations.Content; 10 | import com.emc.documentum.springdata.entitymanager.mapping.DctmAttribute; 11 | import com.emc.documentum.springdata.entitymanager.mapping.DctmEntity; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | @DctmEntity(repository = "persons") 17 | @TypeAlias("person") 18 | public class Person { 19 | 20 | @DctmAttribute("firstname") 21 | private String name; 22 | 23 | @Id 24 | public String _id; 25 | public Integer age; 26 | 27 | @DctmAttribute("sex") 28 | private String gender; 29 | 30 | 31 | private List hobbies = new ArrayList<>(); 32 | 33 | @DctmAttribute("accountnumbers") 34 | private List accountNumbers = new ArrayList<>(); 35 | 36 | @Content 37 | private String content; 38 | 39 | // @Relation 40 | // public Address address; 41 | 42 | // private Content file; 43 | // 44 | // @Content 45 | // public boolean getFileAt(String path) { 46 | // return true; 47 | // } 48 | // 49 | // @Content 50 | // public void setFile(String path) { 51 | // this.file = file; 52 | // } 53 | 54 | public List getAccountNumbers() { 55 | return accountNumbers; 56 | } 57 | 58 | public void setAccountNumbers(List accountNumbers) { 59 | this.accountNumbers = accountNumbers; 60 | } 61 | 62 | public List getHobbies() { 63 | return hobbies; 64 | } 65 | 66 | public void setHobbies(List hobbies) { 67 | this.hobbies = hobbies; 68 | } 69 | 70 | // public Address getAddress() { 71 | // return address; 72 | // } 73 | // 74 | // public void setAddress(Address address) { 75 | // this.address = address; 76 | // } 77 | 78 | public void set_id(String _id) { 79 | this._id = _id; 80 | } 81 | 82 | 83 | public String getName() { 84 | return name; 85 | } 86 | 87 | 88 | public String get_id() { 89 | return _id; 90 | } 91 | 92 | public void setName(String name) { 93 | this.name = name; 94 | } 95 | 96 | public Integer getAge() { 97 | return age; 98 | } 99 | 100 | public void setAge(Integer age) { 101 | this.age = age; 102 | } 103 | 104 | public String getGender() { 105 | return gender; 106 | } 107 | 108 | public void setGender(String gender) { 109 | this.gender = gender; 110 | } 111 | 112 | public Person(String name, Integer age, String gender) { 113 | this.name = name; 114 | this.age = age; 115 | this.gender = gender; 116 | } 117 | 118 | public Person() {} 119 | 120 | @Content 121 | public String getContent() { 122 | return content; 123 | } 124 | 125 | @Content 126 | public void setContent(String path) { 127 | this.content = path; 128 | } 129 | 130 | 131 | } 132 | 133 | -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/core/tests/DctmTemplateTest.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.core.tests; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import java.io.File; 7 | import java.net.URL; 8 | import java.util.List; 9 | 10 | import com.emc.documentum.springdata.core.Loan; 11 | import com.emc.documentum.springdata.core.*; 12 | 13 | import org.junit.Before; 14 | import org.junit.BeforeClass; 15 | import org.junit.Rule; 16 | import org.junit.Test; 17 | import org.junit.rules.ExpectedException; 18 | import org.junit.runner.RunWith; 19 | import org.springframework.beans.factory.annotation.Autowired; 20 | import org.springframework.boot.test.SpringApplicationConfiguration; 21 | import org.springframework.data.authentication.UserCredentials; 22 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 23 | 24 | import com.documentum.fc.common.DfException; 25 | 26 | @RunWith(SpringJUnit4ClassRunner.class) 27 | @SpringApplicationConfiguration(classes = Application.class) 28 | public class DctmTemplateTest { 29 | 30 | private Person p; 31 | 32 | @Autowired 33 | private Documentum dctm; 34 | 35 | @Autowired 36 | private DctmTemplate template; 37 | 38 | @Rule 39 | public ExpectedException expected = ExpectedException.none(); 40 | 41 | @BeforeClass 42 | public static void setUpBeforeClass() throws Exception { 43 | 44 | } 45 | 46 | @Before 47 | public void setUp() { 48 | dctm.setCredentials(new UserCredentials("dmadmin", "demo.demo")); 49 | dctm.setDocBase("corp"); 50 | 51 | } 52 | 53 | // @Test 54 | public void testSpringConfiguration() throws DfException { 55 | System.out.println(p.getName()); 56 | System.out.println(template.findAll(Person.class).size()); 57 | } 58 | 59 | @Test 60 | public void testInsert() throws DfException { 61 | 62 | p = new Person("Rohan", 22, "Male"); 63 | Person insertedPerson = template.create(p); 64 | assertEquals(insertedPerson.getName(), p.getName()); 65 | assertEquals(insertedPerson.getAge(), p.getAge()); 66 | assertEquals(insertedPerson.getGender(), p.getGender()); 67 | 68 | } 69 | 70 | @Test 71 | public void testUpdate() throws DfException { 72 | 73 | p = new Person("Adam", 22, "Female"); 74 | template.create(p); 75 | p.setGender("Male"); 76 | Person updatedPerson = template.update(p); 77 | assertEquals(updatedPerson.getGender(), "Male"); 78 | 79 | } 80 | 81 | @Test 82 | public void testFindById() throws DfException { 83 | 84 | p = new Person("John", 67, "Male"); 85 | Person insertedPerson = template.create(p); 86 | Person obj = template.findById(insertedPerson.get_id(), Person.class); 87 | assertEquals(obj.getName(), p.getName()); 88 | assertEquals(obj.getAge(), p.getAge()); 89 | assertEquals(obj.getGender(), p.getGender()); 90 | 91 | } 92 | 93 | 94 | 95 | public void testForRepeatingAttributes() throws DfException { 96 | 97 | p = new Person("John", 67, "Male"); 98 | p.getAccountNumbers().add(new Double(1979869469)); 99 | p.getAccountNumbers().add(new Double(1979869468)); 100 | Person insertedPerson = template.create(p); 101 | Person obj = template.findById(insertedPerson.get_id(), Person.class); 102 | obj.getAccountNumbers().add(new Double(1979869467)); 103 | obj.getHobbies().add("Reading"); 104 | obj.getHobbies().add("Dancing"); 105 | Person updatedObj = template.update(obj); 106 | assertEquals(updatedObj.getAccountNumbers().size(), 3); 107 | assertEquals(updatedObj.getHobbies().size(), 2); 108 | } 109 | 110 | 111 | @Test(expected = DfException.class) 112 | public void testFindByIdThrowsBadIDException() throws DfException { 113 | 114 | template.findById("this id doesn't exist", Person.class); 115 | } 116 | 117 | @Test 118 | public void testFindAll() throws DfException { 119 | List list1 = template.findAll(Person.class); 120 | p = new Person("Rohan", 22, "Male"); 121 | template.create(p); 122 | List list2 = template.findAll(Person.class); 123 | assertEquals(list1.size() + 1, list2.size()); 124 | } 125 | 126 | @Test 127 | public void testDeleteObject() throws DfException { 128 | p = new Person("Alisha", 22, "Female"); 129 | Person insertedPerson = template.create(p); 130 | List list1 = template.findAll(Person.class); 131 | String id = insertedPerson.get_id(); 132 | String deletedPersonId = template.delete(insertedPerson); 133 | List list2 = template.findAll(Person.class); 134 | assertEquals(id, deletedPersonId); 135 | assertEquals(list1.size() - 1, list2.size()); 136 | } 137 | 138 | @Test 139 | public void testCount() throws DfException { 140 | long count = template.count(Person.class); 141 | assertEquals(template.findAll(Person.class).size(), count); 142 | } 143 | 144 | @Test 145 | public void testSetContent() throws DfException { 146 | Loan loan = new Loan(1000); 147 | template.create(loan); 148 | URL url = this.getClass().getResource("/sample.pdf"); 149 | template.setContent(loan, "pdf", url.getPath()); 150 | String path = template.getContent(loan, "testsample.pdf"); 151 | File file = new File(path); 152 | assertTrue(file.exists()); 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/core/tests/DocumentumTest.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.core.tests; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import com.emc.documentum.springdata.core.Application; 6 | import org.junit.*; 7 | import org.junit.rules.ExpectedException; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.boot.test.SpringApplicationConfiguration; 11 | import org.springframework.data.authentication.UserCredentials; 12 | 13 | import com.documentum.fc.client.IDfSession; 14 | import com.documentum.fc.common.DfException; 15 | import com.emc.documentum.springdata.core.Documentum; 16 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 17 | 18 | @RunWith(SpringJUnit4ClassRunner.class) 19 | @SpringApplicationConfiguration(classes = Application.class) 20 | public class DocumentumTest { 21 | 22 | private UserCredentials credentials; 23 | @Autowired 24 | private Documentum doc; 25 | private String docBase; 26 | @Autowired 27 | private Documentum docWithWrongCredentials; 28 | 29 | @Rule 30 | public ExpectedException expected = ExpectedException.none(); 31 | 32 | 33 | 34 | @Before 35 | public void setup(){ 36 | credentials = new UserCredentials("dmadmin", "demo.demo"); 37 | docBase = "corp"; 38 | doc.setDocBase(docBase); 39 | doc.setCredentials(credentials); 40 | } 41 | 42 | @Test 43 | public void testGetCredentials() throws DfException { 44 | assertEquals(doc.getCredentials(),credentials); 45 | 46 | } 47 | 48 | 49 | @Test 50 | public void testGetSession() throws DfException { 51 | 52 | IDfSession session = doc.getSession(); 53 | assertEquals(session.getDocbaseName(), docBase); 54 | } 55 | 56 | /** 57 | * DfServiceException raised if no host and port information given either as constructor 58 | * arguments or in dfc.properties 59 | * @throws DfException 60 | */ 61 | // @Test 62 | // public void testGetSessionThrowsDfServiceException() throws DfException { 63 | // try { 64 | // Documentum docWithoutHostAndPort = new Documentum(credentials); 65 | // String docBase = "corp"; 66 | // docWithoutHostAndPort.getSession(docBase); 67 | // } 68 | // catch(Exception e) { 69 | // 70 | // expected.expect(DfServiceException.class); 71 | // } 72 | // } 73 | // 74 | 75 | @Test 76 | public void testGetSessionThrowsDfIdentityException() throws DfException{ 77 | 78 | String docBase = "corp"; 79 | UserCredentials wrongCredentials = new UserCredentials("admin", "passwrd"); 80 | docWithWrongCredentials.setCredentials(wrongCredentials); 81 | docWithWrongCredentials.setDocBase(docBase); 82 | docWithWrongCredentials.getSession(); 83 | } 84 | 85 | @Test 86 | public void testDocumentumUserCredentialsStringString() throws DfException { 87 | String docBase = "corp"; 88 | Documentum docCreatedWithPrimaryHostAndPort = new Documentum(credentials, docBase, "172.16.253.160", "1489" ); 89 | IDfSession session = docCreatedWithPrimaryHostAndPort.getSession(); 90 | assertEquals(session.getDocbaseName(), docBase); 91 | } 92 | 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/core/tests/GenericCacheTest.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.core.tests; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.BeforeClass; 6 | import org.junit.Test; 7 | 8 | import com.emc.documentum.springdata.core.GenericCache; 9 | 10 | public class GenericCacheTest { 11 | 12 | static GenericCache cache; 13 | 14 | @BeforeClass 15 | public static void setUpBeforeClass() { 16 | cache = new GenericCache(); 17 | } 18 | 19 | @Test 20 | public void SetAndGetTest(){ 21 | cache.setEntry("key", "value"); 22 | assertEquals(cache.getEntry("key"), "value"); 23 | } 24 | 25 | @Test 26 | public void TestToCheckCachePersistance(){ 27 | 28 | if(cache.getEntry("Key2") == null){ 29 | cache.setEntry("key2", "value"); 30 | } 31 | 32 | assertEquals(cache.getEntry("key2"), "value"); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/entitymanager/mapping/MappingHandlerTest.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.entitymanager.mapping; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.emc.documentum.springdata.entitymanager.annotations.Relation; 7 | import com.emc.documentum.springdata.entitymanager.annotations.RelationshipType; 8 | import com.emc.documentum.springdata.entitymanager.attributes.AttributeType; 9 | 10 | import junit.framework.TestCase; 11 | 12 | /* 13 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 14 | * EMC Confidential: Restricted Internal Distribution 15 | */ 16 | public class MappingHandlerTest { 17 | 18 | public void testGetAttributeMappings() throws Exception { 19 | MappingHandler handler = new MappingHandler(); 20 | ArrayList attributeMappings = handler.getAttributeMappings(LeftEntity.class); 21 | for (AttributeType attributeMapping : attributeMappings) { 22 | System.out.println(attributeMapping); 23 | } 24 | } 25 | 26 | private static final class LeftEntity { 27 | @Relation(name = "mn", value = RelationshipType.ONE_TO_MANY) 28 | private final List rightEntity = new ArrayList<>(); 29 | } 30 | 31 | private static final class RightEntity { 32 | @Relation(name = "mn", value= RelationshipType.ONE_TO_MANY) 33 | private final List leftEntity = new ArrayList<>(); 34 | } 35 | } -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/repository/AbstractTest.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository; 2 | 3 | import com.emc.documentum.springdata.ApplicationConfig; 4 | import com.emc.documentum.springdata.core.Documentum; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.data.authentication.UserCredentials; 8 | import org.springframework.test.context.ContextConfiguration; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | import javax.annotation.PostConstruct; 12 | 13 | /** 14 | * Created by mukheg on 4/20/15. 15 | */ 16 | @RunWith(SpringJUnit4ClassRunner.class) 17 | @ContextConfiguration(classes = ApplicationConfig.class) 18 | public abstract class AbstractTest { 19 | 20 | @Autowired 21 | protected Documentum documentum; 22 | 23 | @PostConstruct 24 | public void setupDocumentum() { 25 | UserCredentials credentials = new UserCredentials("dmadmin", "demo.demo"); 26 | String docBase = "corp"; 27 | documentum.setDocBase(docBase); 28 | documentum.setCredentials(credentials); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/repository/relation/Address.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.relation; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.annotation.Id; 6 | 7 | import com.emc.documentum.springdata.entitymanager.annotations.Relation; 8 | import com.emc.documentum.springdata.entitymanager.annotations.RelationshipType; 9 | import com.emc.documentum.springdata.entitymanager.mapping.DctmEntity; 10 | 11 | /* 12 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 13 | * EMC Confidential: Restricted Internal Distribution 14 | */ 15 | @DctmEntity(repository = "address") 16 | public class Address { 17 | 18 | private String street; 19 | private String city; 20 | private String country; 21 | @Id 22 | private String id; 23 | 24 | @Relation(value=RelationshipType.ONE_TO_MANY, name="address") 25 | private List residents; 26 | 27 | public Address() { 28 | } 29 | 30 | public Address(String street, String city, String country) { 31 | this.street = street; 32 | this.city = city; 33 | this.country = country; 34 | } 35 | 36 | public String getStreet() { 37 | return street; 38 | } 39 | 40 | public void setStreet(String street) { 41 | this.street = street; 42 | } 43 | 44 | public String getCity() { 45 | return city; 46 | } 47 | 48 | public void setCity(String city) { 49 | this.city = city; 50 | } 51 | 52 | public String getCountry() { 53 | return country; 54 | } 55 | 56 | public void setCountry(String country) { 57 | this.country = country; 58 | } 59 | 60 | public String getId() { 61 | return id; 62 | } 63 | 64 | public void setId(String id) { 65 | this.id = id; 66 | } 67 | 68 | @Override 69 | public boolean equals(Object o) { 70 | if (this == o) { return true; } 71 | if (o == null || getClass() != o.getClass()) { return false; } 72 | 73 | Address address = (Address)o; 74 | 75 | if (street != null ? !street.equals(address.street) : address.street != null) { return false; } 76 | if (city != null ? !city.equals(address.city) : address.city != null) { return false; } 77 | if (country != null ? !country.equals(address.country) : address.country != null) { return false; } 78 | return !(id != null ? !id.equals(address.id) : address.id != null); 79 | 80 | } 81 | 82 | @Override 83 | public int hashCode() { 84 | int result = street != null ? street.hashCode() : 0; 85 | result = 31 * result + (city != null ? city.hashCode() : 0); 86 | result = 31 * result + (country != null ? country.hashCode() : 0); 87 | result = 31 * result + (id != null ? id.hashCode() : 0); 88 | return result; 89 | } 90 | 91 | @Override 92 | public String toString() { 93 | return "Address{" + 94 | "street='" + street + '\'' + 95 | ", city='" + city + '\'' + 96 | ", country='" + country + '\'' + 97 | ", id='" + id + '\'' + 98 | '}'; 99 | } 100 | 101 | public List getResidents() { 102 | return residents; 103 | } 104 | 105 | public void setResidents(List residents) { 106 | this.residents = residents; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/repository/relation/Person.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.relation; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.annotation.Id; 6 | import org.springframework.data.annotation.TypeAlias; 7 | 8 | import com.emc.documentum.springdata.core.Loan; 9 | import com.emc.documentum.springdata.entitymanager.annotations.Relation; 10 | import com.emc.documentum.springdata.entitymanager.annotations.RelationshipType; 11 | import com.emc.documentum.springdata.entitymanager.mapping.DctmAttribute; 12 | import com.emc.documentum.springdata.entitymanager.mapping.DctmEntity; 13 | 14 | @DctmEntity(repository = "persons") 15 | @TypeAlias("person") 16 | public class Person { 17 | public Person() { 18 | } 19 | 20 | @Id 21 | public String _id; 22 | 23 | public Integer age; 24 | 25 | @DctmAttribute("firstname") 26 | private String name; 27 | 28 | @DctmAttribute("sex") 29 | private String gender; 30 | 31 | @Relation(value=RelationshipType.ONE_TO_MANY, name="liabilities") 32 | List loans; 33 | 34 | @Relation(value=RelationshipType.ONE_TO_ONE, name="address") 35 | Address address; 36 | 37 | public Address getAddress() { 38 | return address; 39 | } 40 | 41 | public void setAddress(Address address) { 42 | this.address = address; 43 | } 44 | 45 | public List getLoans() { 46 | return loans; 47 | } 48 | 49 | public void setLoans(List loans) { 50 | this.loans = loans; 51 | } 52 | 53 | public String getName() { 54 | return name; 55 | } 56 | 57 | public void set_id(String _id) { 58 | this._id = _id; 59 | } 60 | 61 | public String get_id() { 62 | return _id; 63 | } 64 | 65 | public void setName(String name) { 66 | this.name = name; 67 | } 68 | 69 | public Integer getAge() { 70 | return age; 71 | } 72 | 73 | public void setAge(Integer age) { 74 | this.age = age; 75 | } 76 | 77 | public String getGender() { 78 | return gender; 79 | } 80 | 81 | public void setGender(String gender) { 82 | this.gender = gender; 83 | } 84 | 85 | public Person(String name, Integer age, String gender) { 86 | this.name = name; 87 | this.age = age; 88 | this.gender = gender; 89 | } 90 | 91 | @Override 92 | public String toString() { 93 | return "Person{" + 94 | "_id='" + _id + '\'' + 95 | ", age=" + age + 96 | ", name='" + name + '\'' + 97 | ", gender='" + gender + '\'' + 98 | ", loans=" + loans + 99 | '}'; 100 | } 101 | 102 | @Override 103 | public boolean equals(Object o) { 104 | if (this == o) { return true; } 105 | if (o == null || getClass() != o.getClass()) { return false; } 106 | 107 | Person person = (Person)o; 108 | 109 | if (_id != null ? !_id.equals(person._id) : person._id != null) { return false; } 110 | if (age != null ? !age.equals(person.age) : person.age != null) { return false; } 111 | if (name != null ? !name.equals(person.name) : person.name != null) { return false; } 112 | if (gender != null ? !gender.equals(person.gender) : person.gender != null) { return false; } 113 | return !(loans != null ? !loans.equals(person.loans) : person.loans != null); 114 | 115 | } 116 | 117 | @Override 118 | public int hashCode() { 119 | int result = _id != null ? _id.hashCode() : 0; 120 | result = 31 * result + (age != null ? age.hashCode() : 0); 121 | result = 31 * result + (name != null ? name.hashCode() : 0); 122 | result = 31 * result + (gender != null ? gender.hashCode() : 0); 123 | result = 31 * result + (loans != null ? loans.hashCode() : 0); 124 | return result; 125 | } 126 | } 127 | 128 | -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/repository/relation/PersonRepositoryWithRelation.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.relation; 2 | 3 | import com.emc.documentum.springdata.repository.DctmRepository; 4 | 5 | /* 6 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 7 | * EMC Confidential: Restricted Internal Distribution 8 | */ 9 | public interface PersonRepositoryWithRelation extends DctmRepository { 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/repository/relation/RelationTest.java: -------------------------------------------------------------------------------- 1 | //package com.emc.documentum.springdata.repository.relation; 2 | // 3 | //import static org.junit.Assert.assertEquals; 4 | //import static org.junit.Assert.assertNotNull; 5 | //import static org.junit.Assert.assertNull; 6 | //import static org.junit.Assert.assertTrue; 7 | //import static org.junit.Assert.fail; 8 | // 9 | //import java.util.Arrays; 10 | //import java.util.List; 11 | // 12 | //import javax.annotation.PostConstruct; 13 | // 14 | //import org.apache.log4j.Logger; 15 | //import org.junit.After; 16 | //import org.junit.Before; 17 | //import org.junit.Ignore; 18 | //import org.junit.Test; 19 | //import org.junit.runner.RunWith; 20 | //import org.springframework.beans.factory.annotation.Autowired; 21 | //import org.springframework.data.authentication.UserCredentials; 22 | //import org.springframework.test.context.ContextConfiguration; 23 | //import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 24 | // 25 | //import com.documentum.fc.client.DfQuery; 26 | //import com.documentum.fc.client.IDfCollection; 27 | //import com.documentum.fc.client.IDfPersistentObject; 28 | //import com.documentum.fc.client.IDfQuery; 29 | //import com.documentum.fc.client.IDfSession; 30 | //import com.documentum.fc.client.IDfTypedObject; 31 | //import com.documentum.fc.common.DfException; 32 | //import com.documentum.fc.common.DfId; 33 | //import com.emc.documentum.springdata.*; 34 | //import com.emc.documentum.springdata.core.Documentum; 35 | //import com.emc.documentum.springdata.core.Loan; 36 | //import com.emc.documentum.springdata.log.AutowiredLogger; 37 | //import com.emc.documentum.springdata.repository.support.SimpleDctmRepository; 38 | // 39 | ///* 40 | // * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 41 | // * EMC Confidential: Restricted Internal Distribution 42 | // */ 43 | //public class RelationTest { 44 | // 45 | // public static final String RELATION_QUERY = "select * from dm_relation where relation_name=\'%s\' and parent_id=\'%s\'"; 46 | // //Somehow IntelliJ cribs about this but the runtime manages to autowire these correctly 47 | // @Autowired 48 | // private PersonRepositoryWithRelation personRepository; 49 | // @Autowired 50 | // private LoanRepository loanRepository; 51 | // @Autowired 52 | // private Documentum documentum; 53 | // @AutowiredLogger 54 | // private Logger logger = Logger.getLogger(SimpleDctmRepository.class); 55 | // 56 | // @PostConstruct 57 | // public void setupDocumentum() { 58 | // UserCredentials credentials = new UserCredentials("dmadmin", "demo.demo"); 59 | // String docBase = "corp"; 60 | // documentum.setDocBase(docBase); 61 | // documentum.setCredentials(credentials); 62 | // } 63 | // 64 | // @Before 65 | // public void setUp() throws Exception { 66 | // } 67 | // 68 | // @After 69 | // public void cleanUp() { 70 | // logger.info("Deleting objects: "); 71 | // Iterable createdObjects = personRepository.findAll(); 72 | // for (Person createdObject : createdObjects) { 73 | // logger.info(createdObject); 74 | // } 75 | // loanRepository.delete(loanRepository.findAll()); 76 | // personRepository.delete(createdObjects); 77 | // } 78 | // 79 | // @Test 80 | // @Ignore("Test to test tests") 81 | // public void testFindAll() throws Exception { 82 | // Iterable all = personRepository.findAll(); 83 | // System.out.println("================="); 84 | // for (Person person : all) { 85 | // System.out.println(person); 86 | // } 87 | // System.out.println("================="); 88 | // System.out.println(); 89 | // } 90 | // 91 | // @Test 92 | // public void testSaveObjectWithoutSavingRelation() { 93 | // Person person = new Person("Peter Parker", 19, "male"); 94 | // personRepository.save(person); 95 | // assertNotNull("Base object not saved " + person, person.get_id()); 96 | // Person personDctmObject = personRepository.findOne(person.get_id()); 97 | // assertEquals("Object not found in repository", person.get_id(), personDctmObject.get_id()); 98 | // assertNull(personDctmObject.getAddress()); 99 | // assertTrue(personDctmObject.getLoans().size() == 0); 100 | // } 101 | // 102 | // @Test 103 | // public void testSaveObjectWithOneToOneRelation() throws Exception { 104 | // Person person = new Person("Peter Parker", 19, "male"); 105 | // Address address = new Address("SomeStreet", "SomeCity", "SomeCountry"); 106 | // person.setAddress(address); 107 | // personRepository.save(person); 108 | // assertNotNull("Related object not saved " + address, address.getId()); 109 | // assertNotNull("Base object not saved " + person, person.get_id()); 110 | // verifyOneToOneRelation(person, address); 111 | // } 112 | // 113 | // @Test 114 | // public void testUpdateOneToOneRelation() throws DfException { 115 | // Person person = new Person("Peter Parker", 19, "male"); 116 | // Address address = new Address("SomeStreet", "SomeCity", "SomeCountry"); 117 | // personRepository.save(person); 118 | // person.setAddress(address); 119 | // personRepository.save(person); 120 | // assertNotNull("Related object not saved " + address, address.getId()); 121 | // assertNotNull("Base object not saved " + person, person.get_id()); 122 | // verifyOneToOneRelation(person, address); 123 | // } 124 | // 125 | // private void verifyOneToOneRelation(Person person, Address address) throws DfException { 126 | // String queryString = String.format(RELATION_QUERY, "address", person.get_id()); 127 | // IDfQuery query = new DfQuery(queryString); 128 | // IDfSession session = documentum.getSession(); 129 | // 130 | // IDfCollection children = query.execute(session, 0); 131 | // 132 | // assertTrue("No related objects found", children.next()); 133 | // IDfTypedObject child = children.getTypedObject(); 134 | // IDfPersistentObject childObject = session.getObject(new DfId(child.getString("child_id"))); 135 | // assertTrue(address.getId().equalsIgnoreCase(childObject.getObjectId().toString())); 136 | // } 137 | // 138 | // @Test 139 | // public void testSaveObjectWithOneToManyRelation() throws Exception { 140 | // Person person = new Person("Peter Parker", 19, "male"); 141 | // Loan loan = new Loan(100000); 142 | // Loan loan2 = new Loan(200000); 143 | // List loans = Arrays.asList(loan, loan2); 144 | // person.setLoans(loans); 145 | // 146 | // personRepository.save(person); 147 | // assertNotNull("Related object not saved " + loan, loan.getLoanId()); 148 | // assertNotNull("Related object not saved " + loan2, loan2.getLoanId()); 149 | // assertNotNull("Base object not saved " + person, person.get_id()); 150 | // verifyOneToManyRelation(person, loans); 151 | // } 152 | // 153 | // private void verifyOneToManyRelation(Person person, List loans) throws DfException { 154 | // String queryString = String.format(RELATION_QUERY, "liabilities", person.get_id()); 155 | // IDfQuery query = new DfQuery(queryString); 156 | // IDfSession session = documentum.getSession(); 157 | // 158 | // IDfCollection children = query.execute(session, 0); 159 | // 160 | // while(children.next()) { 161 | // IDfTypedObject child = children.getTypedObject(); 162 | // IDfPersistentObject childObject = session.getObject(new DfId(child.getString("child_id"))); 163 | // 164 | // boolean found = false; 165 | // for (Loan loan : loans) { 166 | // if(loan.getLoanId().equalsIgnoreCase(childObject.getObjectId().toString())) { 167 | // found = true; 168 | // break; 169 | // } 170 | // } 171 | // if(!found){ 172 | // fail("Relation not created "); 173 | // } 174 | // } 175 | // } 176 | //} 177 | -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/repository/relation/mn/Address.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.relation.mn; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.annotation.Id; 6 | 7 | import com.emc.documentum.springdata.entitymanager.annotations.Relation; 8 | import com.emc.documentum.springdata.entitymanager.annotations.RelationshipType; 9 | import com.emc.documentum.springdata.entitymanager.mapping.DctmEntity; 10 | 11 | /* 12 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 13 | * EMC Confidential: Restricted Internal Distribution 14 | */ 15 | @DctmEntity(repository = "address_new") 16 | public class Address { 17 | 18 | private String street; 19 | private String city; 20 | private String country; 21 | @Id 22 | private String id; 23 | 24 | @Relation(value=RelationshipType.ONE_TO_MANY, name="address") 25 | private List residents; 26 | 27 | public Address() { 28 | } 29 | 30 | public Address(String street, String city, String country) { 31 | this.street = street; 32 | this.city = city; 33 | this.country = country; 34 | } 35 | 36 | public String getStreet() { 37 | return street; 38 | } 39 | 40 | public void setStreet(String street) { 41 | this.street = street; 42 | } 43 | 44 | public String getCity() { 45 | return city; 46 | } 47 | 48 | public void setCity(String city) { 49 | this.city = city; 50 | } 51 | 52 | public String getCountry() { 53 | return country; 54 | } 55 | 56 | public void setCountry(String country) { 57 | this.country = country; 58 | } 59 | 60 | public String getId() { 61 | return id; 62 | } 63 | 64 | public void setId(String id) { 65 | this.id = id; 66 | } 67 | 68 | @Override 69 | public boolean equals(Object o) { 70 | if (this == o) { return true; } 71 | if (o == null || getClass() != o.getClass()) { return false; } 72 | 73 | Address address = (Address)o; 74 | 75 | if (street != null ? !street.equals(address.street) : address.street != null) { return false; } 76 | if (city != null ? !city.equals(address.city) : address.city != null) { return false; } 77 | if (country != null ? !country.equals(address.country) : address.country != null) { return false; } 78 | return !(id != null ? !id.equals(address.id) : address.id != null); 79 | 80 | } 81 | 82 | @Override 83 | public int hashCode() { 84 | int result = street != null ? street.hashCode() : 0; 85 | result = 31 * result + (city != null ? city.hashCode() : 0); 86 | result = 31 * result + (country != null ? country.hashCode() : 0); 87 | result = 31 * result + (id != null ? id.hashCode() : 0); 88 | return result; 89 | } 90 | 91 | @Override 92 | public String toString() { 93 | return "Address{" + 94 | "street='" + street + '\'' + 95 | ", city='" + city + '\'' + 96 | ", country='" + country + '\'' + 97 | ", id='" + id + '\'' + 98 | '}'; 99 | } 100 | 101 | public List getResidents() { 102 | return residents; 103 | } 104 | 105 | public void setResidents(List residents) { 106 | this.residents = residents; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/repository/relation/mn/AddressRepository.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.relation.mn; 2 | 3 | import com.emc.documentum.springdata.repository.DctmRepository; 4 | 5 | /* 6 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 7 | * EMC Confidential: Restricted Internal Distribution 8 | */ 9 | public interface AddressRepository extends DctmRepository { 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/repository/relation/mn/ManyToManyRelationTest.java: -------------------------------------------------------------------------------- 1 | //package com.emc.documentum.springdata.repository.relation.mn; 2 | // 3 | //import static org.junit.Assert.assertEquals; 4 | //import static org.junit.Assert.assertTrue; 5 | // 6 | //import java.util.Arrays; 7 | //import java.util.List; 8 | // 9 | //import javax.annotation.PostConstruct; 10 | // 11 | //import org.apache.log4j.Logger; 12 | //import org.junit.After; 13 | //import org.junit.Before; 14 | //import org.junit.Ignore; 15 | //import org.junit.Test; 16 | //import org.junit.runner.RunWith; 17 | //import org.springframework.beans.factory.annotation.Autowired; 18 | //import org.springframework.data.authentication.UserCredentials; 19 | //import org.springframework.test.context.ContextConfiguration; 20 | //import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 21 | // 22 | //import com.emc.documentum.springdata.ApplicationConfig; 23 | //import com.emc.documentum.springdata.core.Documentum; 24 | //import com.emc.documentum.springdata.log.AutowiredLogger; 25 | //import com.emc.documentum.springdata.repository.support.SimpleDctmRepository; 26 | // 27 | ///* 28 | // * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 29 | // * EMC Confidential: Restricted Internal Distribution 30 | // */ 31 | // 32 | //public class ManyToManyRelationTest { 33 | // 34 | // public static final String RELATION_QUERY = "select * from dm_relation where relation_name=\'%s\' and parent_id=\'%s\'"; 35 | // //Somehow IntelliJ cribs about this but the runtime manages to autowire these correctly 36 | // @Autowired 37 | // private PersonRepositoryWithRelationMn personRepositoryWithRelationMn; 38 | // @Autowired 39 | // private AddressRepository addressRepository; 40 | // @Autowired 41 | // private Documentum documentum; 42 | // @AutowiredLogger 43 | // private Logger logger = Logger.getLogger(SimpleDctmRepository.class); 44 | // 45 | // @PostConstruct 46 | // public void setupDocumentum() { 47 | // UserCredentials credentials = new UserCredentials("dmadmin", "demo.demo"); 48 | // String docBase = "corp"; 49 | // documentum.setDocBase(docBase); 50 | // documentum.setCredentials(credentials); 51 | // } 52 | // 53 | // @Before 54 | // public void setUp() throws Exception { 55 | // } 56 | // 57 | // @After 58 | // public void cleanUp() { 59 | // logger.info("Deleting objects: "); 60 | // Iterable createdObjects = personRepositoryWithRelationMn.findAll(); 61 | // for (Person createdObject : createdObjects) { 62 | // logger.info(createdObject); 63 | // } 64 | // 65 | // addressRepository.delete(addressRepository.findAll()); 66 | // personRepositoryWithRelationMn.delete(createdObjects); 67 | // } 68 | // 69 | // @Test 70 | // public void noOp() { 71 | ////Just to delete stuff 72 | // } 73 | // 74 | // @Test 75 | // @Ignore("Test to test tests") 76 | // public void testFindAll() throws Exception { 77 | // Iterable all = personRepositoryWithRelationMn.findAll(); 78 | // System.out.println("================="); 79 | // for (Person person : all) { 80 | // System.out.println(person); 81 | // } 82 | // System.out.println("================="); 83 | // System.out.println(); 84 | // } 85 | // 86 | // @Test 87 | // public void testManyToManyRelation() throws Exception { 88 | // Person bruceWayne = new Person("Bruce Wayne", 35, "male"); 89 | // Person alfredPennyworth = new Person("Alfred Pennyworth", 63, "male"); 90 | // 91 | // Address wayneManor = new Address("Wayne Street", "Gotham City", "DC"); 92 | // Address batCave = new Address("Classified", "Classified", "Classified"); 93 | // Address starLabs = new Address("S.T.A.R. Labs", "Austin", "Texas"); 94 | // 95 | // List
bruceWayneAddresses = Arrays.asList(wayneManor, batCave, starLabs); 96 | // bruceWayne.setAddress(bruceWayneAddresses); 97 | // alfredPennyworth.setAddress(Arrays.asList(wayneManor, batCave)); 98 | // 99 | // personRepositoryWithRelationMn.save(bruceWayne); 100 | // personRepositoryWithRelationMn.save(alfredPennyworth); 101 | // 102 | // Person foundBruceWayne = personRepositoryWithRelationMn.findOne(bruceWayne.get_id()); 103 | // assertEquals("Some addresses not found", bruceWayneAddresses.size(), foundBruceWayne.getAddress().size()); 104 | // 105 | // int foundCount = bruceWayneAddresses.size(); 106 | // for (Address bruceWayneAddress : bruceWayneAddresses) { 107 | // for (Address address : foundBruceWayne.getAddress()) { 108 | // if(bruceWayneAddress.equals(address)) { 109 | // foundCount--; 110 | // break; 111 | // } 112 | // } 113 | // } 114 | // 115 | // assertEquals("Some Addresses not found", 0, foundCount); 116 | // Address savedManor = addressRepository.findOne(wayneManor.getId()); 117 | // Address savedBatCave = addressRepository.findOne(batCave.getId()); 118 | // Address savedStarLabs = addressRepository.findOne(starLabs.getId()); 119 | // assertEquals("Incorrect resident count", 2, savedManor.getResidents().size()); 120 | // assertEquals("Incorrect resident count", 2, savedBatCave.getResidents().size()); 121 | // assertEquals("Incorrect resident count", 1, savedStarLabs.getResidents().size()); 122 | // } 123 | // 124 | // @Test 125 | // public void testUpdateRelation() throws Exception { 126 | // Person bruceWayne = new Person("Bruce Wayne", 35, "male"); 127 | // Person alfredPennyworth = new Person("Alfred Pennyworth", 63, "male"); 128 | // 129 | // Address wayneManor = new Address("Wayne Street", "Gotham City", "DC"); 130 | // Address batCave = new Address("Classified", "Classified", "Classified"); 131 | // Address starLabs = new Address("S.T.A.R. Labs", "Austin", "Texas"); 132 | // 133 | // List
bruceWayneAddresses = Arrays.asList(wayneManor, batCave, starLabs); 134 | // 135 | // personRepositoryWithRelationMn.save(bruceWayne); 136 | // personRepositoryWithRelationMn.save(alfredPennyworth); 137 | // 138 | // Person foundBruceWayne = personRepositoryWithRelationMn.findOne(bruceWayne.get_id()); 139 | // assertTrue(foundBruceWayne.getAddress() == null || foundBruceWayne.getAddress().size() == 0); 140 | // 141 | // bruceWayne.setAddress(bruceWayneAddresses); 142 | // alfredPennyworth.setAddress(Arrays.asList(wayneManor, batCave)); 143 | // 144 | // personRepositoryWithRelationMn.save(bruceWayne); 145 | // personRepositoryWithRelationMn.save(alfredPennyworth); 146 | // 147 | // foundBruceWayne = personRepositoryWithRelationMn.findOne(bruceWayne.get_id()); 148 | // assertEquals("Some addresses not found", bruceWayneAddresses.size(), foundBruceWayne.getAddress().size()); 149 | // 150 | // int foundCount = bruceWayneAddresses.size(); 151 | // for (Address bruceWayneAddress : bruceWayneAddresses) { 152 | // for (Address address : foundBruceWayne.getAddress()) { 153 | // if(bruceWayneAddress.equals(address)) { 154 | // foundCount--; 155 | // break; 156 | // } 157 | // } 158 | // } 159 | // 160 | // assertEquals("Some Addresses not found", 0, foundCount); 161 | // Address savedManor = addressRepository.findOne(wayneManor.getId()); 162 | // Address savedBatCave = addressRepository.findOne(batCave.getId()); 163 | // Address savedStarLabs = addressRepository.findOne(starLabs.getId()); 164 | // assertEquals("Incorrect resident count", 2, savedManor.getResidents().size()); 165 | // assertEquals("Incorrect resident count", 2, savedBatCave.getResidents().size()); 166 | // assertEquals("Incorrect resident count", 1, savedStarLabs.getResidents().size()); 167 | // } 168 | // 169 | // @Test 170 | // public void testManyToManyRelationReverse() { 171 | // Person bruceWayne = new Person("Bruce Wayne", 35, "male"); 172 | // Person alfredPennyworth = new Person("Alfred Pennyworth", 63, "male"); 173 | // 174 | // Address wayneManor = new Address("Wayne Street", "Gotham City", "DC"); 175 | // Address batCave = new Address("Classified", "Classified", "Classified"); 176 | // Address starLabs = new Address("S.T.A.R. Labs", "Austin", "Texas"); 177 | // 178 | // List
bruceWayneAddresses = Arrays.asList(wayneManor, batCave, starLabs); 179 | // 180 | // wayneManor.setResidents(Arrays.asList(bruceWayne, alfredPennyworth)); 181 | // batCave.setResidents(Arrays.asList(bruceWayne, alfredPennyworth)); 182 | // starLabs.setResidents(Arrays.asList(bruceWayne)); 183 | // addressRepository.save(Arrays.asList(wayneManor, batCave, starLabs)); 184 | // 185 | // Person foundBruceWayne = personRepositoryWithRelationMn.findOne(bruceWayne.get_id()); 186 | // assertEquals("Some addresses not found", bruceWayneAddresses.size(), foundBruceWayne.getAddress().size()); 187 | // 188 | // int foundCount = bruceWayneAddresses.size(); 189 | // for (Address bruceWayneAddress : bruceWayneAddresses) { 190 | // for (Address address : foundBruceWayne.getAddress()) { 191 | // if(bruceWayneAddress.equals(address)) { 192 | // foundCount--; 193 | // break; 194 | // } 195 | // } 196 | // } 197 | // 198 | // assertEquals("Some Addresses not found", 0, foundCount); 199 | // Address savedManor = addressRepository.findOne(wayneManor.getId()); 200 | // Address savedBatCave = addressRepository.findOne(batCave.getId()); 201 | // Address savedStarLabs = addressRepository.findOne(starLabs.getId()); 202 | // assertEquals("Incorrect resident count", 2, savedManor.getResidents().size()); 203 | // assertEquals("Incorrect resident count", 2, savedBatCave.getResidents().size()); 204 | // assertEquals("Incorrect resident count", 1, savedStarLabs.getResidents().size()); 205 | // } 206 | //} 207 | -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/repository/relation/mn/Person.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.relation.mn; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.annotation.Id; 6 | import org.springframework.data.annotation.TypeAlias; 7 | 8 | import com.emc.documentum.springdata.entitymanager.annotations.Relation; 9 | import com.emc.documentum.springdata.entitymanager.annotations.RelationshipType; 10 | import com.emc.documentum.springdata.entitymanager.mapping.DctmAttribute; 11 | import com.emc.documentum.springdata.entitymanager.mapping.DctmEntity; 12 | 13 | @DctmEntity(repository = "persons") 14 | @TypeAlias("person") 15 | public class Person { 16 | public Person() { 17 | } 18 | 19 | @Id 20 | public String _id; 21 | 22 | public Integer age; 23 | 24 | @DctmAttribute("firstname") 25 | private String name; 26 | 27 | @DctmAttribute("sex") 28 | private String gender; 29 | 30 | @Relation(value=RelationshipType.ONE_TO_MANY, name="address") 31 | List
address; 32 | 33 | public List
getAddress() { 34 | return address; 35 | } 36 | 37 | public void setAddress(List
address) { 38 | this.address = address; 39 | } 40 | 41 | public String getName() { 42 | return name; 43 | } 44 | 45 | public void set_id(String _id) { 46 | this._id = _id; 47 | } 48 | 49 | public String get_id() { 50 | return _id; 51 | } 52 | 53 | public void setName(String name) { 54 | this.name = name; 55 | } 56 | 57 | public Integer getAge() { 58 | return age; 59 | } 60 | 61 | public void setAge(Integer age) { 62 | this.age = age; 63 | } 64 | 65 | public String getGender() { 66 | return gender; 67 | } 68 | 69 | public void setGender(String gender) { 70 | this.gender = gender; 71 | } 72 | 73 | public Person(String name, Integer age, String gender) { 74 | this.name = name; 75 | this.age = age; 76 | this.gender = gender; 77 | } 78 | 79 | @Override 80 | public String toString() { 81 | return "Person{" + 82 | "_id='" + _id + '\'' + 83 | ", age=" + age + 84 | ", name='" + name + '\'' + 85 | ", gender='" + gender + '\'' + 86 | '}'; 87 | } 88 | 89 | @Override 90 | public boolean equals(Object o) { 91 | if (this == o) { return true; } 92 | if (o == null || getClass() != o.getClass()) { return false; } 93 | 94 | Person person = (Person)o; 95 | 96 | if (_id != null ? !_id.equals(person._id) : person._id != null) { return false; } 97 | if (age != null ? !age.equals(person.age) : person.age != null) { return false; } 98 | if (name != null ? !name.equals(person.name) : person.name != null) { return false; } 99 | if (gender != null ? !gender.equals(person.gender) : person.gender != null) { return false; } 100 | return !(address != null ? !address.equals(person.address) : person.address != null); 101 | 102 | } 103 | 104 | @Override 105 | public int hashCode() { 106 | int result = _id != null ? _id.hashCode() : 0; 107 | result = 31 * result + (age != null ? age.hashCode() : 0); 108 | result = 31 * result + (name != null ? name.hashCode() : 0); 109 | result = 31 * result + (gender != null ? gender.hashCode() : 0); 110 | result = 31 * result + (address != null ? address.hashCode() : 0); 111 | return result; 112 | } 113 | } 114 | 115 | -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/repository/relation/mn/PersonRepositoryWithRelationMn.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.relation.mn; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import com.emc.documentum.springdata.repository.DctmRepository; 6 | 7 | /* 8 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 9 | * EMC Confidential: Restricted Internal Distribution 10 | */ 11 | public interface PersonRepositoryWithRelationMn extends DctmRepository { 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/repository/support/DctmRepositoryWithContentTest.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.support; 2 | 3 | import static org.junit.Assert.assertTrue; 4 | 5 | import java.io.File; 6 | import java.net.URL; 7 | import java.util.LinkedList; 8 | import java.util.List; 9 | 10 | import javax.annotation.PostConstruct; 11 | 12 | import org.apache.log4j.Logger; 13 | import org.junit.After; 14 | import org.junit.Before; 15 | import org.junit.Test; 16 | import org.junit.runner.RunWith; 17 | import org.springframework.beans.factory.annotation.Autowired; 18 | import org.springframework.data.authentication.UserCredentials; 19 | import org.springframework.test.context.ContextConfiguration; 20 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 21 | 22 | import com.emc.documentum.springdata.ApplicationConfig; 23 | import com.emc.documentum.springdata.LoanRepository; 24 | import com.emc.documentum.springdata.core.Documentum; 25 | import com.emc.documentum.springdata.core.Loan; 26 | import com.emc.documentum.springdata.log.AutowiredLogger; 27 | 28 | /* 29 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 30 | * EMC Confidential: Restricted Internal Distribution 31 | */ 32 | @RunWith(SpringJUnit4ClassRunner.class) 33 | @ContextConfiguration(classes = ApplicationConfig.class) 34 | public class DctmRepositoryWithContentTest { 35 | 36 | //Somehow IntelliJ cribs about this but the runtime manages to autowire these correctly 37 | @Autowired 38 | private LoanRepository loanRepository; 39 | @Autowired 40 | private Documentum documentum; 41 | @AutowiredLogger 42 | private Logger logger = Logger.getLogger(SimpleDctmRepository.class); 43 | 44 | private List filesToClean = new LinkedList<>(); 45 | 46 | @PostConstruct 47 | public void setupDocumentum() { 48 | UserCredentials credentials = new UserCredentials("dmadmin", "demo.demo"); 49 | String docBase = "corp"; 50 | documentum.setDocBase(docBase); 51 | documentum.setCredentials(credentials); 52 | } 53 | 54 | @Before 55 | public void setUp() throws Exception { 56 | } 57 | 58 | @After 59 | public void cleanUp() { 60 | logger.info("Deleting objects: "); 61 | Iterable createdObjects = loanRepository.findAll(); 62 | for (Loan createdObject : createdObjects) { 63 | logger.info(createdObject); 64 | } 65 | loanRepository.delete(createdObjects); 66 | for (File file : filesToClean) { 67 | if(!file.delete()) { 68 | System.out.println(String.format("Failed to delete: %s", file.getAbsolutePath())); 69 | } 70 | } 71 | } 72 | 73 | @Test 74 | public void testSetContentByObject() { 75 | Loan loan = new Loan(100000); 76 | Loan loanAsDctmObject = loanRepository.save(loan); 77 | System.out.println(String.format("Created loan {%s}", loanAsDctmObject)); 78 | URL url = this.getClass().getResource("/sample.pdf"); 79 | 80 | loanRepository.setContent(loan, "pdf", url.getPath()); 81 | String path = loanRepository.getContent(loan, "returnedObject" + System.currentTimeMillis() + ".pdf"); 82 | 83 | File returnedFile = new File(path); 84 | filesToClean.add(returnedFile); 85 | assertTrue(returnedFile.exists()); 86 | } 87 | } -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/repository/support/QueryDslDctmRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.support; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNotNull; 5 | 6 | import java.util.Arrays; 7 | import java.util.HashMap; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | import javax.annotation.PostConstruct; 12 | 13 | import org.apache.log4j.Logger; 14 | import org.junit.After; 15 | import org.junit.Ignore; 16 | import org.junit.Test; 17 | import org.junit.runner.RunWith; 18 | import org.springframework.beans.factory.annotation.Autowired; 19 | import org.springframework.data.authentication.UserCredentials; 20 | import org.springframework.test.context.ContextConfiguration; 21 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 22 | 23 | import com.emc.documentum.springdata.ApplicationConfig; 24 | import com.emc.documentum.springdata.Person; 25 | import com.emc.documentum.springdata.PersonQueryDslRepository; 26 | import com.emc.documentum.springdata.core.Documentum; 27 | import com.emc.documentum.springdata.log.AutowiredLogger; 28 | 29 | /* 30 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 31 | * EMC Confidential: Restricted Internal Distribution 32 | */ 33 | @RunWith(SpringJUnit4ClassRunner.class) 34 | @ContextConfiguration(classes = ApplicationConfig.class) 35 | public class QueryDslDctmRepositoryTest { 36 | 37 | @Autowired 38 | PersonQueryDslRepository personQueryDslRepository; 39 | @Autowired 40 | private Documentum documentum; 41 | @AutowiredLogger 42 | private Logger logger = Logger.getLogger(SimpleDctmRepository.class); 43 | 44 | @After 45 | public void cleanUp() { 46 | logger.info("Deleting objects: "); 47 | Iterable createdObjects = personQueryDslRepository.findAll(); 48 | for (Person createdObject : createdObjects) { 49 | logger.info(createdObject); 50 | } 51 | personQueryDslRepository.delete(createdObjects); 52 | } 53 | 54 | @PostConstruct 55 | public void setupDocumentum() { 56 | UserCredentials credentials = new UserCredentials("dmadmin", "demo.demo"); 57 | String docBase = "corp"; 58 | documentum.setDocBase(docBase); 59 | documentum.setCredentials(credentials); 60 | } 61 | 62 | @Test 63 | @Ignore("This is not the test you are looking for {Jedi hand wave}.") 64 | public void genericTest() { 65 | /* 66 | QPerson person = new QPerson("Bruce"); 67 | BooleanBuilder builder = new BooleanBuilder( ); 68 | builder.and(person.name.eq("test")).and(person.name.eq("testsadfkljf;ajsdf")); 69 | System.out.println(builder.getValue()); 70 | */ 71 | } 72 | 73 | @Test 74 | public void testFindBySingleAttribute() throws Exception { 75 | Person bruceWayne = new Person("Bruce Wayne", 35, "male"); 76 | logger.info("Trying to save: " + bruceWayne); 77 | Person savedBruceWayne = personQueryDslRepository.save(bruceWayne); 78 | logger.info("Saved: " + savedBruceWayne); 79 | assertEquals("They are different people", bruceWayne, savedBruceWayne); 80 | 81 | List byName = personQueryDslRepository.findByName("Bruce Wayne"); 82 | assertEquals(byName.get(0), bruceWayne); 83 | } 84 | 85 | @Test 86 | public void testFindByTwoAttributesUsingOr() throws Exception { 87 | //Create collection to save 88 | Person bruceWayne = new Person("Bruce Wayne", 35, "male"); 89 | Person peterParker = new Person("Peter Parker", 19, "male"); 90 | Person barbaraGordon = new Person("Barbara Gordon", 28, "female"); 91 | Map personMap = new HashMap<>(); 92 | personMap.put("Bruce Wayne", bruceWayne); 93 | personMap.put("Barbara Gordon", barbaraGordon); 94 | 95 | List objectsForInsertion = Arrays.asList(bruceWayne, peterParker, barbaraGordon); 96 | 97 | //Do save 98 | personQueryDslRepository.save(objectsForInsertion); 99 | 100 | List personList = personQueryDslRepository.findByNameOrGender("Bruce Wayne", "female"); 101 | assertEquals("Count mismatch", 2, personList.size()); 102 | 103 | for (Person person : personList) { 104 | logger.info(String.format("Found: [%s]", person.toString())); 105 | assertNotNull(String.format("Couldn't find [%s]", person), personMap.get(person.getName())); 106 | } 107 | } 108 | 109 | @Test 110 | public void testFindByTwoAttributesUsingAnd() throws Exception { 111 | //Create collection to save 112 | Person bruceWayne = new Person("Bruce Wayne", 35, "male"); //The real Bruce Wayne 113 | Person thomasElliot = new Person("Bruce Wayne", 31, "male"); //Hush 114 | 115 | List objectsForInsertion = Arrays.asList(bruceWayne, thomasElliot); 116 | 117 | //Do save 118 | personQueryDslRepository.save(objectsForInsertion); 119 | List personList = personQueryDslRepository.findByNameAndAge("Bruce Wayne", 35); 120 | assertEquals("Count mismatch", 1, personList.size()); 121 | } 122 | 123 | @Test 124 | @Ignore("Range queries not implemented") 125 | public void testFindInRange() throws Exception { 126 | Person bruceWayne = new Person("Bruce Wayne", 35, "male"); 127 | Person peterParker = new Person("Peter Parker", 19, "male"); 128 | Person barbaraGordon = new Person("Barbara Gordon", 28, "female"); 129 | Map personMap = new HashMap<>(); 130 | personMap.put("Bruce Wayne", bruceWayne); 131 | personMap.put("Barbara Gordon", barbaraGordon); 132 | 133 | List objectsForInsertion = Arrays.asList(bruceWayne, peterParker, barbaraGordon); 134 | 135 | //Do save 136 | personQueryDslRepository.save(objectsForInsertion); 137 | 138 | List personList = personQueryDslRepository.findByAgeBetween(17, 20); 139 | assertEquals("Count mismatch", 2, personList.size()); 140 | 141 | for (Person person : personList) { 142 | logger.info(String.format("Found: [%s]", person.toString())); 143 | assertNotNull(String.format("Unexpected person found [%s]", person), personMap.get(person.getName())); 144 | } 145 | } 146 | } -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/repository/support/QueryDslDctmRepositoryWithContentTest.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.support; 2 | 3 | import java.io.File; 4 | import java.net.URL; 5 | import java.util.LinkedList; 6 | import java.util.List; 7 | 8 | import javax.annotation.PostConstruct; 9 | 10 | import org.apache.log4j.Logger; 11 | import org.junit.After; 12 | import org.junit.Before; 13 | import org.junit.Test; 14 | import org.junit.runner.RunWith; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.data.authentication.UserCredentials; 17 | import org.springframework.test.context.ContextConfiguration; 18 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 19 | 20 | import com.emc.documentum.springdata.ApplicationConfig; 21 | import com.emc.documentum.springdata.LoanQueryDslDctmRepository; 22 | import com.emc.documentum.springdata.core.Documentum; 23 | import com.emc.documentum.springdata.core.Loan; 24 | import com.emc.documentum.springdata.log.AutowiredLogger; 25 | 26 | import junit.framework.TestCase; 27 | 28 | /* 29 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 30 | * EMC Confidential: Restricted Internal Distribution 31 | */ 32 | @RunWith(SpringJUnit4ClassRunner.class) 33 | @ContextConfiguration(classes = ApplicationConfig.class) 34 | public class QueryDslDctmRepositoryWithContentTest extends TestCase { 35 | 36 | //Somehow IntelliJ cribs about this but the runtime manages to autowire these correctly 37 | @Autowired 38 | private LoanQueryDslDctmRepository loanRepository; 39 | @Autowired 40 | private Documentum documentum; 41 | @AutowiredLogger 42 | private Logger logger = Logger.getLogger(SimpleDctmRepository.class); 43 | 44 | private List filesToClean = new LinkedList<>(); 45 | 46 | @PostConstruct 47 | public void setupDocumentum() { 48 | UserCredentials credentials = new UserCredentials("dmadmin", "demo.demo"); 49 | String docBase = "corp"; 50 | documentum.setDocBase(docBase); 51 | documentum.setCredentials(credentials); 52 | } 53 | 54 | @Before 55 | public void setUp() throws Exception { 56 | } 57 | 58 | @After 59 | public void cleanUp() { 60 | logger.info("Deleting objects: "); 61 | Iterable createdObjects = loanRepository.findAll(); 62 | for (Loan createdObject : createdObjects) { 63 | logger.info(createdObject); 64 | } 65 | loanRepository.delete(createdObjects); 66 | for (File file : filesToClean) { 67 | if(!file.delete()) { 68 | System.out.println(String.format("Failed to delete: %s", file.getAbsolutePath())); 69 | } 70 | } 71 | } 72 | 73 | @Test 74 | public void testSetContentByObject() { 75 | Loan loan = new Loan(100000); 76 | Loan loanAsDctmObject = loanRepository.save(loan); 77 | System.out.println(String.format("Created loan {%s}", loanAsDctmObject)); 78 | 79 | Loan loan2 = new Loan(500000); 80 | Loan loanAsDctmObject2 = loanRepository.save(loan2); 81 | System.out.println(String.format("Created loan {%s}", loanAsDctmObject2)); 82 | URL url = this.getClass().getResource("/sample.pdf"); 83 | loanRepository.setContent(loanAsDctmObject2, "pdf", url.getPath()); 84 | 85 | List loanList = loanRepository.findByAmountGreaterThan(200000); 86 | assertEquals("Count mismatch", 1, loanList.size()); 87 | 88 | String path = loanRepository.getContent(loanList.get(0), "returnedObject" + System.currentTimeMillis() + ".pdf"); 89 | 90 | File returnedFile = new File(path); 91 | filesToClean.add(returnedFile); 92 | assertTrue(returnedFile.exists()); 93 | } 94 | } -------------------------------------------------------------------------------- /src/test/java/com/emc/documentum/springdata/repository/support/StringBasedDctmQueryTest.java: -------------------------------------------------------------------------------- 1 | package com.emc.documentum.springdata.repository.support; 2 | 3 | /* 4 | * Copyright (c) 2015 EMC Corporation. All Rights Reserved. 5 | * EMC Confidential: Restricted Internal Distribution 6 | */ 7 | 8 | import static org.junit.Assert.assertEquals; 9 | import static org.junit.Assert.assertTrue; 10 | 11 | import java.util.Arrays; 12 | import java.util.List; 13 | 14 | import org.junit.After; 15 | import org.junit.Before; 16 | import org.junit.Test; 17 | import org.springframework.beans.factory.annotation.Autowired; 18 | 19 | import com.emc.documentum.springdata.Person; 20 | import com.emc.documentum.springdata.PersonQueryDslRepository; 21 | import com.emc.documentum.springdata.repository.AbstractTest; 22 | 23 | public class StringBasedDctmQueryTest extends AbstractTest { 24 | 25 | @Autowired 26 | PersonQueryDslRepository personQueryDslRepository; 27 | 28 | @Before 29 | @After 30 | public void cleanUp() { 31 | System.out.println("Deleting objects: "); 32 | Iterable createdObjects = personQueryDslRepository.findAll(); 33 | for (Person createdObject : createdObjects) { 34 | System.out.println(createdObject); 35 | } 36 | personQueryDslRepository.delete(createdObjects); 37 | } 38 | 39 | @Test 40 | public void testStringBasedQuery() throws Exception { 41 | Person wadeWilson = new Person("Wade Wilson", 73, "male"); 42 | Person bruceWayne = new Person("Bruce Wayne", 35, "male"); 43 | List personsToSave = Arrays.asList(wadeWilson, bruceWayne); 44 | 45 | personQueryDslRepository.save(wadeWilson); 46 | personQueryDslRepository.save(bruceWayne); 47 | 48 | List foundPersons = personQueryDslRepository.findByAgeOrName("Bruce Wayne", 73); 49 | 50 | assertEquals("Incorrect Sizes found", 2, foundPersons.size()); 51 | int foundCount = 0; 52 | System.out.println("==============="); 53 | for (Person person : foundPersons) { 54 | for (Person foundPerson : personsToSave) { 55 | if(person.equals(foundPerson)) { 56 | foundCount++; break; 57 | } 58 | } 59 | } 60 | assertEquals("Some saved people not found", 2, foundCount); 61 | System.out.println("==============="); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/resources/dfc.properties: -------------------------------------------------------------------------------- 1 | dfc.docbroker.host[0]=172.16.253.160 2 | dfc.docbroker.port[0]=1489 3 | -------------------------------------------------------------------------------- /src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=INFO, DebugAppender 2 | 3 | #Debug logging 4 | log4j.appender.DebugAppender=org.apache.log4j.RollingFileAppender 5 | log4j.appender.DebugAppender.Threshold=DEBUG 6 | log4j.appender.DebugAppender.File=activityLog.log 7 | log4j.appender.DebugAppender.MaxFileSize=200KB 8 | log4j.appender.DebugAppender.MaxBackupIndex=5 9 | log4j.appender.DebugAppender.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.DebugAppender.layout.ConversionPattern=%d{DATE} %t - %m%n -------------------------------------------------------------------------------- /src/test/resources/sample.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Enterprise-Content-Management/spring-data-dctm/c6bb5cda53d250f1b74b00336322ebaccc788f9d/src/test/resources/sample.pdf -------------------------------------------------------------------------------- /test.txt: -------------------------------------------------------------------------------- 1 | Add a file to test the new repo under PlayGround. 2 | edited the file. 3 | Rohan Edited the file. 4 | -------------------------------------------------------------------------------- /testsample.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Enterprise-Content-Management/spring-data-dctm/c6bb5cda53d250f1b74b00336322ebaccc788f9d/testsample.pdf --------------------------------------------------------------------------------