use of org.alfresco.service.cmr.coci.CheckOutCheckInService in project alfresco-remote-api by Alfresco.
the class PutMethodTest method setUp.
@Before
public void setUp() throws Exception {
searchService = ctx.getBean("SearchService", SearchService.class);
fileFolderService = ctx.getBean("FileFolderService", FileFolderService.class);
nodeService = ctx.getBean("NodeService", NodeService.class);
transactionService = ctx.getBean("transactionService", TransactionService.class);
webDAVHelper = ctx.getBean("webDAVHelper", WebDAVHelper.class);
authenticationService = ctx.getBean("authenticationService", MutableAuthenticationService.class);
personService = ctx.getBean("PersonService", PersonService.class);
lockService = ctx.getBean("LockService", LockService.class);
contentService = ctx.getBean("contentService", ContentService.class);
checkOutCheckInService = ctx.getBean("CheckOutCheckInService", CheckOutCheckInService.class);
permissionService = ctx.getBean("PermissionService", PermissionService.class);
namespaceService = ctx.getBean("namespaceService", NamespaceService.class);
actionService = ctx.getBean("ActionService", ActionService.class);
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
repositoryHelper = (Repository) ctx.getBean("repositoryHelper");
companyHomeNodeRef = repositoryHelper.getCompanyHome();
txn = transactionService.getUserTransaction();
txn.begin();
createUser(USER1_NAME);
createUser(USER2_NAME);
InputStream testDataIS = getClass().getClassLoader().getResourceAsStream(TEST_DATA_FILE_NAME);
InputStream davLockInfoAdminIS = getClass().getClassLoader().getResourceAsStream(DAV_LOCK_INFO_ADMIN);
InputStream davLockInfoUser2IS = getClass().getClassLoader().getResourceAsStream(DAV_LOCK_INFO_USER2);
testDataFile = IOUtils.toByteArray(testDataIS);
davLockInfoAdminFile = IOUtils.toByteArray(davLockInfoAdminIS);
davLockInfoUser2File = IOUtils.toByteArray(davLockInfoUser2IS);
testDataIS.close();
davLockInfoAdminIS.close();
davLockInfoUser2IS.close();
// Create a test file with versionable aspect and content
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
versionableDocName = "doc-" + GUID.generate();
properties.put(ContentModel.PROP_NAME, versionableDocName);
versionableDoc = nodeService.createNode(companyHomeNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(ContentModel.USER_MODEL_URI, versionableDocName), ContentModel.TYPE_CONTENT, properties).getChildRef();
contentService.getWriter(versionableDoc, ContentModel.PROP_CONTENT, true).putContent("WebDAVTestContent");
nodeService.addAspect(versionableDoc, ContentModel.ASPECT_VERSIONABLE, null);
txn.commit();
txn = transactionService.getUserTransaction();
txn.begin();
}
use of org.alfresco.service.cmr.coci.CheckOutCheckInService in project alfresco-remote-api by Alfresco.
the class NodeVersionsRelation method revertById.
@Operation("revert")
@WebApiDescription(title = "Revert Version", description = "Reverts (ie. promotes) specified version to become a new, most recent, version", successStatus = HttpServletResponse.SC_OK)
public Node revertById(String nodeId, String versionId, VersionOptions versionOptions, Parameters parameters, WithResponse withResponse) {
Version v = findVersion(nodeId, versionId);
if (v != null) {
CheckOutCheckInService cociService = sr.getCheckOutCheckInService();
NodeRef nodeRef = v.getVersionedNodeRef();
String versionComment = versionOptions.getComment();
VersionType versionType = VersionType.MINOR;
Boolean versionMajor = versionOptions.getMajorVersion();
if ((versionMajor != null) && (versionMajor)) {
versionType = VersionType.MAJOR;
}
Map<String, Serializable> versionProperties = new HashMap<>(2);
versionProperties.put(VersionModel.PROP_VERSION_TYPE, versionType);
if (versionComment != null) {
versionProperties.put(VersionModel.PROP_DESCRIPTION, versionComment);
}
// cancel editing if we want to revert
if (sr.getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY)) {
nodeRef = cociService.cancelCheckout(nodeRef);
}
// TODO review default for deep and/or whether we should make it an option
versionService.revert(nodeRef, v, false);
// Checkout/Checkin the node - to store the new version in version history
NodeRef wcNodeRef = cociService.checkout(nodeRef);
cociService.checkin(wcNodeRef, versionProperties);
// get latest version
v = versionService.getVersionHistory(nodeRef).getHeadVersion();
Node node = nodes.getFolderOrDocumentFullInfo(v.getFrozenStateNodeRef(), null, null, parameters, null);
mapVersionInfo(v, node);
return node;
}
throw new EntityNotFoundException(nodeId + "-" + versionId);
}
use of org.alfresco.service.cmr.coci.CheckOutCheckInService in project acs-community-packaging by Alfresco.
the class UnlockDocEvaluator method evaluate.
/**
* @see org.alfresco.web.action.ActionEvaluator#evaluate(org.alfresco.web.bean.repository.Node)
*/
public boolean evaluate(Node node) {
if (node.isLocked()) {
FacesContext fc = FacesContext.getCurrentInstance();
CheckOutCheckInService checkOutCheckInService = (CheckOutCheckInService) FacesHelper.getManagedBean(fc, "CheckoutCheckinService");
if (checkOutCheckInService.getWorkingCopy(node.getNodeRef()) == null) {
return true;
}
}
return false;
}
use of org.alfresco.service.cmr.coci.CheckOutCheckInService in project acs-community-packaging by Alfresco.
the class ForumsCheckinDocEvaluator method evaluate.
/**
* @see org.alfresco.web.action.ActionEvaluator#evaluate(org.alfresco.web.bean.repository.Node)
*/
public boolean evaluate(Node node) {
boolean allow = false;
if (node.hasAspect(ContentModel.ASPECT_WORKING_COPY) && node.getProperties().get(ContentModel.PROP_WORKING_COPY_MODE) == null) {
if (node.hasAspect(ForumModel.ASPECT_DISCUSSABLE)) {
CheckOutCheckInService checkOutCheckInService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getCheckOutCheckInService();
// get the original locked node (via the copiedfrom aspect)
NodeRef lockedNodeRef = checkOutCheckInService.getCheckedOut(node.getNodeRef());
if (lockedNodeRef != null) {
Node lockedNode = new Node(lockedNodeRef);
allow = (node.hasPermission(PermissionService.CHECK_IN) && lockedNode.hasPermission(PermissionService.CONTRIBUTOR));
}
} else {
// there is no discussion so just check they have checkin permission for the node
allow = node.hasPermission(PermissionService.CHECK_IN);
}
}
return allow;
}
use of org.alfresco.service.cmr.coci.CheckOutCheckInService in project alfresco-remote-api by Alfresco.
the class TestActions method canGetActionDefinitionsForNode.
@Test
public void canGetActionDefinitionsForNode() throws Exception {
final String person1 = account1PersonIt.next();
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1));
// Get the actions available on the -my- node-ref alias
{
ListResponse<ActionDefinition> actionDefs = actions.getActionDefinitionsForNode("-my-", emptyParams, 200);
assertNotNull("Action definition list should not be null", actionDefs);
assertFalse("Action definition list should not be empty", actionDefs.getList().isEmpty());
// Check defaults, given that no paging params were sent in the request
assertEquals(Paging.DEFAULT_MAX_ITEMS, actionDefs.getPaging().getMaxItems().intValue());
assertEquals(Paging.DEFAULT_SKIP_COUNT, actionDefs.getPaging().getSkipCount().intValue());
// Check ActionDefinition fields
List<ActionDefinition> actionDefinitions = actionDefs.getList().stream().filter(ad -> ad.getName().equals("add-features")).collect(Collectors.toList());
assertEquals(1, actionDefinitions.size());
ActionDefinition action = actionDefinitions.get(0);
assertEquals("add-features", action.getId());
assertEquals("add-features", action.getName());
assertEquals("Add aspect", action.getTitle());
assertEquals("This will add an aspect to the matched item.", action.getDescription());
// Applicable types
assertEquals(0, action.getApplicableTypes().size());
assertEquals(false, action.isTrackStatus());
// Parameter definitions
assertEquals(1, action.getParameterDefinitions().size());
ActionDefinition.ParameterDefinition paramDefs = action.getParameterDefinitions().get(0);
assertEquals(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, paramDefs.getName());
assertEquals("d:qname", paramDefs.getType());
assertEquals(true, paramDefs.isMandatory());
assertEquals("Aspect", paramDefs.getDisplayLabel());
assertEquals(false, paramDefs.isMultiValued());
assertEquals("ac-aspects", paramDefs.getParameterConstraintName());
}
AuthenticationUtil.setFullyAuthenticatedUser(person1);
// Get the actions for a "checked out" node - there should be a "check-in" action present.
// Inspect the fields, to make sure that they're all there. Especially applicableTypes, as
// this isn't available on any of the actions that appear for the "-my-" alias in the test above.
{
NodeRef nodeForCheckout = nodeService.createNode(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, getMyNodeId()), ContentModel.ASSOC_CONTAINS, QName.createQName("test", "test-node-checkedout"), ContentModel.TYPE_CONTENT).getChildRef();
CheckOutCheckInService coci = applicationContext.getBean("CheckOutCheckInService", CheckOutCheckInService.class);
coci.checkout(nodeForCheckout);
ListResponse<ActionDefinition> actionDefs = actions.getActionDefinitionsForNode(nodeForCheckout.getId(), emptyParams, 200);
List<ActionDefinition> actionDefinitions = actionDefs.getList().stream().filter(ad -> ad.getName().equals("check-in")).collect(Collectors.toList());
assertEquals(1, actionDefinitions.size());
ActionDefinition action = actionDefinitions.get(0);
assertEquals("check-in", action.getId());
assertEquals("check-in", action.getName());
assertEquals("Check in", action.getTitle());
assertEquals("This will check in the matched content.", action.getDescription());
// Applicable types
assertEquals(1, action.getApplicableTypes().size());
assertEquals("cm:content", action.getApplicableTypes().get(0));
assertEquals(false, action.isTrackStatus());
// Parameter definitions
assertEquals(2, action.getParameterDefinitions().size());
// "description"
ActionDefinition.ParameterDefinition paramDefs = action.getParameterDefinitions().get(0);
assertEquals(CheckInActionExecuter.PARAM_DESCRIPTION, paramDefs.getName());
assertEquals("d:text", paramDefs.getType());
assertEquals(false, paramDefs.isMandatory());
assertEquals("Description", paramDefs.getDisplayLabel());
assertEquals(false, paramDefs.isMultiValued());
assertEquals(null, paramDefs.getParameterConstraintName());
// "minorChange"
paramDefs = action.getParameterDefinitions().get(1);
assertEquals(CheckInActionExecuter.PARAM_MINOR_CHANGE, paramDefs.getName());
assertEquals("d:boolean", paramDefs.getType());
assertEquals(false, paramDefs.isMandatory());
assertEquals("Minor change", paramDefs.getDisplayLabel());
assertEquals(false, paramDefs.isMultiValued());
assertEquals(null, paramDefs.getParameterConstraintName());
}
String myNode = getMyNodeId();
NodeRef validNode = nodeService.createNode(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, myNode), ContentModel.ASSOC_CONTAINS, QName.createQName("test", "test-node"), ContentModel.TYPE_CONTENT).getChildRef();
// Get the actions available using a specific node ID
{
ListResponse<ActionDefinition> actionDefs = actions.getActionDefinitionsForNode(validNode.getId(), emptyParams, 200);
assertNotNull("Action definition list should not be null", actionDefs);
assertFalse("Action definition list should not be empty", actionDefs.getList().isEmpty());
}
// Basic/default paging and sorting
checkBasicPagingAndSorting(// Expected
() -> actionService.getActionDefinitions(validNode).stream().sorted(comparing(org.alfresco.service.cmr.action.ActionDefinition::getName)).map(ParameterizedItemDefinition::getName).collect(Collectors.toList()), // Actual results
paging -> actions.getActionDefinitionsForNode(validNode.getId(), createParams(paging, null), 200));
// Test explicit sorting by title
checkSorting(// Expected
() -> actionService.getActionDefinitions(validNode).stream().sorted(comparing(org.alfresco.service.cmr.action.ActionDefinition::getTitle, nullsFirst(naturalOrder()))).map(act -> new Pair<>(act.getName(), act.getTitle())).collect(Collectors.toList()), // Actual results
(paging, orderBy) -> actions.getActionDefinitionsForNode(validNode.getId(), createParams(paging, orderBy), 200), "title");
// Test explicit sorting by name
checkSorting(// Expected
() -> actionService.getActionDefinitions(validNode).stream().sorted(comparing(org.alfresco.service.cmr.action.ActionDefinition::getName, nullsFirst(naturalOrder()))).map(act -> new Pair<>(act.getName(), act.getTitle())).collect(Collectors.toList()), // Actual results
(paging, orderBy) -> actions.getActionDefinitionsForNode(validNode.getId(), createParams(paging, orderBy), 200), "name");
// Badly formed request -> 400
{
// -1 is not acceptable
PublicApiClient.Paging paging = getPaging(0, -1);
actions.getActionDefinitionsForNode(validNode.getId(), createParams(paging, null), 400);
}
// Non-existent node ID
{
NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "750a2867-ecfa-478c-8343-fa0e39d27be3");
assertFalse("Test pre-requisite: node must not exist", nodeService.exists(nodeRef));
actions.getActionDefinitionsForNode(nodeRef.getId(), emptyParams, 404);
}
// Unauthorized -> 401
{
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1, "invalid-password"));
actions.getActionDefinitionsForNode(validNode.getId(), emptyParams, 401);
}
}
Aggregations