All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.emc.documentum.springdata.core.DctmTemplate Maven / Gradle / Ivy

The newest version!
package com.emc.documentum.springdata.core;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;

import com.documentum.fc.common.DfException;
import com.emc.documentum.springdata.entitymanager.EntityPersistenceManager;
import com.emc.documentum.springdata.entitymanager.EntityTypeHandler;
import com.emc.documentum.springdata.repository.query.DctmQuery;


@Controller
public class DctmTemplate implements DctmOperations {

  private final EntityTypeHandler entityTypeManager;
  private final EntityPersistenceManager entityPersistenceManager;

  @Autowired
  public DctmTemplate(EntityPersistenceManager entityPersistenceManager, EntityTypeHandler entityTypeManager) {
    this.entityPersistenceManager = entityPersistenceManager;
    this.entityTypeManager = entityTypeManager;
  }

  @Override
  public  T create(T objectToSave) throws DfException {
    Assert.notNull(objectToSave);
    String repoObjectName = getRepositoryObjectName(objectToSave);
    return entityPersistenceManager.createObject(repoObjectName, objectToSave);
  }

  @Override
  public  String delete(T objectToDelete) throws DfException {
    Assert.notNull(objectToDelete);
    String repoObjectName = getRepositoryObjectName(objectToDelete);
    return entityPersistenceManager.deleteObject(repoObjectName, objectToDelete);
  }

  @Override
  public  String deleteById(ID objectToDeleteId) throws DfException {
    Assert.notNull(objectToDeleteId);
    return entityPersistenceManager.deleteObject(objectToDeleteId.toString());
  }

  @Override
  public  List findAll(Class entityClass) throws DfException {
    return find(null, entityClass);
  }

  @Override
  public  List find(DctmQuery query, Class entityClass) throws DfException {
    Assert.notNull(entityClass);
    String repoObjectName = getRepositoryName(entityClass);
    return query == null ? doFindAll(entityClass, repoObjectName) : entityPersistenceManager.find(entityClass, repoObjectName, query);
  }

  private  List doFindAll(Class entityClass, String repoObjectName) throws DfException {
    return entityPersistenceManager.findAllObjects(entityClass, repoObjectName);
  }

  @Override
  public  T findById(String id, Class entityClass) throws DfException {
    Assert.notNull(id);
    Assert.notNull(entityClass);
    return entityPersistenceManager.findById(id, entityClass);
  }
  
  @Override
  public long count(Class entityClass) throws DfException {
  Assert.notNull(entityClass);
  String repoObjectName = getRepositoryName(entityClass);
  return entityPersistenceManager.count(entityClass, repoObjectName);
  }

  @Override
  public  T update(T objectToUpdate) throws DfException {
    return entityPersistenceManager.update(objectToUpdate);
  }

  @Override
  public  String getRepositoryObjectName(T obj) {
    Assert.notNull(obj);
    return getRepositoryName(obj.getClass());
  }

  @Override
  public String getRepositoryName(Class entityClass) {
    Assert.notNull(entityClass);
    return entityTypeManager.getEntityObjectName(entityClass);
  }

  @Override
  public  void setContent(T object, String contentType, String path) throws DfException {
      entityPersistenceManager.setContent(object, contentType, path);
  }

  @Override
  public  String getContent(T object, String path) throws DfException {
      return entityPersistenceManager.getContent(object, path);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy