![JAR search and dependency download from the Maven repository](/logo.png)
org.alfresco.mock.test.MockVersionService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of alfresco-tests Show documentation
Show all versions of alfresco-tests Show documentation
This is a jar project based on mock classes to test fastly the alfresco applications
The newest version!
package org.alfresco.mock.test;
import static org.alfresco.model.ContentModel.ASSOC_CONTAINS;
import static org.alfresco.model.ContentModel.PROP_CONTENT;
import static org.alfresco.model.ContentModel.PROP_CREATED;
import static org.alfresco.model.ContentModel.PROP_NAME;
import static org.alfresco.model.ContentModel.PROP_VERSION_LABEL;
import static org.alfresco.model.ContentModel.PROP_VERSION_TYPE;
import static org.alfresco.model.ContentModel.TYPE_CONTENT;
import static org.alfresco.repo.version.Version2Model.CHILD_QNAME_VERSIONS;
import static org.alfresco.repo.version.Version2Model.CHILD_QNAME_VERSION_HISTORIES;
import static org.alfresco.repo.version.Version2Model.PROP_QNAME_FROZEN_MODIFIED;
import static org.alfresco.repo.version.Version2Model.PROP_QNAME_FROZEN_NODE_REF;
import static org.alfresco.repo.version.Version2Model.PROP_QNAME_VERSIONED_NODE_ID;
import static org.alfresco.repo.version.Version2Model.STORE_ID;
import static org.alfresco.service.cmr.repository.StoreRef.PROTOCOL_WORKSPACE;
import static org.alfresco.service.namespace.NamespaceService.CONTENT_MODEL_PREFIX;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.alfresco.repo.version.Version2Model;
import org.alfresco.repo.version.VersionServicePolicies.CalculateVersionLabelPolicy;
import org.alfresco.service.cmr.repository.AspectMissingException;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.MimetypeService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.version.ReservedVersionNameException;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionHistory;
import org.alfresco.service.cmr.version.VersionService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.springframework.beans.factory.annotation.Autowired;
public class MockVersionService implements VersionService, Serializable {
@Autowired
private NodeService nodeService;
@Autowired
private ContentService contentService;
@Autowired
private MimetypeService mimetypeService;
@Autowired
private NamespaceService namespaceService;
private Map versionHistories = new HashMap();
@Override
public StoreRef getVersionStoreReference() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean isAVersion(NodeRef nodeRef) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isVersioned(NodeRef nodeRef) {
// TODO Auto-generated method stub
return false;
}
@Override
public Version createVersion(NodeRef nodeRef, Map versionProperties)
throws ReservedVersionNameException, AspectMissingException {
Collection versions = createVersion(nodeRef, versionProperties, true);
return versions.toArray(new Version[0])[versions.size() - 1];
}
@Override
public Collection createVersion(NodeRef nodeRef, Map versionProperties,
boolean versionChildren) throws ReservedVersionNameException, AspectMissingException {
byte[] text = (byte[]) versionProperties.getOrDefault(PROP_CONTENT.getLocalName(), new byte[] {});
String name = versionProperties.getOrDefault(PROP_NAME.getLocalName(), System.currentTimeMillis()).toString();
InputStream inputStream = new ByteArrayInputStream(text);
ContentWriter writer = contentService.getWriter(nodeRef, PROP_CONTENT, true);
writer.setMimetype(mimetypeService.getMimetype(mimetypeService.getExtension(name)));
writer.putContent(inputStream);
String version = versionProperties.getOrDefault(PROP_VERSION_LABEL.getLocalName(), "").toString();
String versionType = versionProperties.getOrDefault(Version2Model.PROP_VERSION_TYPE, "").toString();
nodeService.setProperty(nodeRef, PROP_VERSION_LABEL, version);
nodeService.setProperty(nodeRef, PROP_VERSION_TYPE, versionProperties.get(Version2Model.PROP_VERSION_TYPE));
VersionHistory versionHistory = versionHistories.get(nodeRef);
if (versionHistory == null)
versionHistory = new MockVersionHistory();
NodeRef versionStore = nodeService.getRootNode(new StoreRef(PROTOCOL_WORKSPACE, STORE_ID));
Map properties = new HashMap();
NodeRef parentVersion = nodeService.getChildByName(versionStore, ASSOC_CONTAINS, nodeRef.getId());
if (parentVersion == null) {
properties.put(PROP_QNAME_VERSIONED_NODE_ID, nodeRef.getId());
properties.put(PROP_NAME, nodeRef.getId());
properties.put(PROP_CREATED, new Date());
parentVersion = nodeService.createNode(versionStore, CHILD_QNAME_VERSION_HISTORIES,
QName.createQName(CONTENT_MODEL_PREFIX, nodeRef.getId(), namespaceService), TYPE_CONTENT,
properties).getChildRef();
try {
TimeUnit.MILLISECONDS.sleep(1);
} catch (InterruptedException e) {
}
}
properties = new HashMap();
properties.put(PROP_NAME, name);
properties.put(PROP_QNAME_FROZEN_NODE_REF, nodeRef.getId());
properties.put(PROP_VERSION_LABEL, version);
properties.put(PROP_VERSION_TYPE, versionType);
properties.put(PROP_QNAME_FROZEN_MODIFIED, new Date());
properties.put(PROP_CREATED, new Date());
NodeRef versionedNode = nodeService
.createNode(parentVersion, CHILD_QNAME_VERSIONS,
QName.createQName(CONTENT_MODEL_PREFIX, name, namespaceService), TYPE_CONTENT, properties)
.getChildRef();
inputStream = new ByteArrayInputStream(text);
writer = contentService.getWriter(versionedNode, PROP_CONTENT, true);
writer.setMimetype(mimetypeService.getMimetype(mimetypeService.getExtension(name)));
writer.putContent(inputStream);
MockVersion mockVersion = new MockVersion(versionedNode, nodeRef, versionProperties);
List list = (List) versionHistory.getAllVersions();
list.add(0, mockVersion);
versionHistories.put(nodeRef, versionHistory);
return versionHistory.getAllVersions();
}
@Override
public Collection createVersion(Collection nodeRefs, Map versionProperties)
throws ReservedVersionNameException, AspectMissingException {
// TODO Auto-generated method stub
return null;
}
@Override
public VersionHistory getVersionHistory(NodeRef nodeRef) throws AspectMissingException {
return versionHistories.get(nodeRef);
}
@Override
public Version getCurrentVersion(NodeRef nodeRef) {
// TODO Auto-generated method stub
return null;
}
@Override
public void revert(NodeRef nodeRef) {
// TODO Auto-generated method stub
}
@Override
public void revert(NodeRef nodeRef, boolean deep) {
// TODO Auto-generated method stub
}
@Override
public void revert(NodeRef nodeRef, Version version) {
// TODO Auto-generated method stub
}
@Override
public void revert(NodeRef nodeRef, Version version, boolean deep) {
// TODO Auto-generated method stub
}
@Override
public NodeRef restore(NodeRef nodeRef, NodeRef parentNodeRef, QName assocTypeQName, QName assocQName) {
// TODO Auto-generated method stub
return null;
}
@Override
public NodeRef restore(NodeRef nodeRef, NodeRef parentNodeRef, QName assocTypeQName, QName assocQName,
boolean deep) {
// TODO Auto-generated method stub
return null;
}
@Override
public void deleteVersionHistory(NodeRef nodeRef) throws AspectMissingException {
// TODO Auto-generated method stub
}
@Override
public void deleteVersion(NodeRef nodeRef, Version version) {
// TODO Auto-generated method stub
}
@Override
public void ensureVersioningEnabled(NodeRef nodeRef, Map versionProperties) {
// TODO Auto-generated method stub
}
@Override
public void registerVersionLabelPolicy(QName typeQName, CalculateVersionLabelPolicy policy) {
// TODO Auto-generated method stub
}
public void setNodeService(NodeService nodeService) {
this.nodeService = nodeService;
}
public void setContentService(ContentService contentService) {
this.contentService = contentService;
}
public void setMimetypeService(MimetypeService mimetypeService) {
this.mimetypeService = mimetypeService;
}
public void setNamespaceService(NamespaceService namespaceService) {
this.namespaceService = namespaceService;
}
public void init() {
versionHistories.clear();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy