private void cancelCheckoutAndDeleteDocumentWithAssertion(string checkedoutDocumentId) { logger.log("Trying to cancel checkouting and deleting document. Checkedouted Document id = " + checkedoutDocumentId); cmisPropertiesType properties = objectPropertiesExists(checkedoutDocumentId); if (!isValueNotSet(properties) && !isValueNotSet(properties.Items)) { object checkedout = searchAndAssertPropertyByName(properties.Items, CHECKED_OUT_PROPERTY, false); object versionSerriesId = checkedoutDocumentId; if (!isValueNotSet(checkedout) && (bool)checkedout) { logger.log("Object was checkouted. Trying to receive VersionSeriesId"); versionSerriesId = searchAndAssertPropertyByName(properties.Items, VERSION_SERIES_ID_PROPERTY, false); logger.log("Trying to cancel checkouting..."); cancelCheckOutAndAssert(checkedoutDocumentId); logger.log("Checkouting was canceled. Original Document id = " + versionSerriesId); } else { logger.log("Checkout canceling was skipped because Document was not checkouted"); } if (!isValueNotSet(versionSerriesId) && !isValueNotSet(objectPropertiesExists((string)versionSerriesId))) { deleteAndAssertObject((string)versionSerriesId); } else { logger.log("Document deleting was skipped because Document id was not recognized"); } } else { logger.log("Skipping checkout canceling and object deleting because object with " + checkedoutDocumentId + " id is not exists"); } }
private void assertObjectProperties(cmisPropertiesType properties, string filter) { if (filter == null) { return; } Assert.IsNotNull(filter, "Incorrect filter"); Assert.IsNotNull(properties, "Object properties is null"); Assert.IsNotNull(properties.Items, "Object properties is null"); bool anyProperties = false; if (filter.Equals(ANY_PROPERTY_FILTER)) { filter = NAME_PROPERTY + "," + OBJECT_IDENTIFIER_PROPERTY; anyProperties = true; } string[] expectedProperties = filter.Replace(" ", "").Split(",".ToCharArray()); if (!anyProperties) { Assert.IsTrue(getSize(properties.Items) == getSize(expectedProperties), "Expected properties size doesn't equal to received properties size"); } HashSet <string> propertiesSet = new HashSet <string>(); foreach (cmisProperty property in properties.Items) { propertiesSet.Add(property.propertyDefinitionId); } foreach (string propertyId in expectedProperties) { Assert.IsTrue(propertiesSet.Contains(propertyId), "Expected property '" + propertyId + "' is not found for object"); } }
public static NameValueCollection ToNameValueCollection(this cmisPropertiesType cmisProperties) { NameValueCollection nameValueCollection = new NameValueCollection(); if (cmisProperties.Items != null) { foreach (var item in cmisProperties.Items) { nameValueCollection[string.IsNullOrEmpty(item.localName) ? item.propertyDefinitionId : item.localName] = item.stringValue; } } return(nameValueCollection); }
public static cmisPropertiesType ToCmisPropertiesType(TextContent textContent) { var properties = new cmisPropertiesType(); var items = new List <cmisProperty>(); items.Add(new cmisPropertyId() { localName = CmisPropertyDefinitionId.BaseTypeId, propertyDefinitionId = CmisPropertyDefinitionId.BaseTypeId, value = new string[] { "cmis:document" } }); items.Add(new cmisPropertyId() { localName = "UserId", propertyDefinitionId = CmisPropertyDefinitionId.CreatedBy, value = new string[] { textContent.UserId } }); items.Add(new cmisPropertyDateTime() { localName = "UtcCreationDate", propertyDefinitionId = CmisPropertyDefinitionId.CreationDate, value = new[] { textContent.UtcCreationDate } }); items.Add(new cmisPropertyDateTime() { localName = "UtcLastModificationDate", propertyDefinitionId = CmisPropertyDefinitionId.LastModificationDate, value = new[] { textContent.UtcLastModificationDate } }); items.Add(new cmisPropertyString() { localName = "UserKey", propertyDefinitionId = CmisPropertyDefinitionId.Name, value = new[] { textContent.UserKey } }); items.Add(new cmisPropertyId() { localName = "IntegrateId", propertyDefinitionId = CmisPropertyDefinitionId.ObjectId, value = new[] { textContent.IntegrateId } }); items.Add(new cmisPropertyId() { localName = "SchemaName", propertyDefinitionId = CmisPropertyDefinitionId.ObjectTypeId, value = new[] { textContent.SchemaName } }); items.Add(new cmisPropertyString() { localName = "ParentUUID", propertyDefinitionId = CmisPropertyDefinitionId.ParentId, value = new[] { textContent.ParentUUID } }); foreach (var item in textContent) { if (!item.Key.StartsWith("__")) { items.Add(ToCmisProperty(item)); } } properties.Items = items.ToArray(); return(properties); }
private static cmisProperty searchForProperty(cmisPropertiesType properties, string propertyName) { if ((null != properties) && (null != properties.Items) && (properties.Items.Length > 0) && (null != propertyName) && !"".Equals(propertyName)) { foreach (cmisProperty property in properties.Items) { string name = getPropertyName(property); if ((null != name) && name.Equals(propertyName)) { return(property); } } } return(null); }
// TODO: policies // TODO: addACEs // TODO: removeACEs public void testLatestVersionPropertiesReceiving() { if (!isVersioningAllowed()) { Assert.Skip(VERSIONING_NOT_SUPPORTTED_MESSAGE); } FileableObject documentCreator = new FileableObject(enumTypesOfFileableObjects.documents, getAndAssertRootFolder(), getAndAssertDocumentTypeId(), null, enumVersioningState.major, true); string documentId = createAndAssertObject(documentCreator, false).ObjectId; documentId = createAndAssertVersionedDocument(documentId, 6, true); cmisPropertiesType initialMajorVersionProperties = getAndAssertLatestVersionProperties(documentId, ANY_PROPERTY_FILTER, true); documentId = createAndAssertVersionedDocument(documentId, 7, false); getAndAssertLatestVersionProperties(documentId, ANY_PROPERTY_FILTER, true); cmisPropertiesType secondMajorVersionProperties = getAndAssertLatestVersionProperties(documentId, ANY_PROPERTY_FILTER, true); assertValuesEquality(NAME_PROPERTY, searchAndAssertPropertyByName(initialMajorVersionProperties.Items, NAME_PROPERTY, false), searchAndAssertPropertyByName(secondMajorVersionProperties.Items, NAME_PROPERTY, false)); assertValuesEquality(MAJOR_VERSION_PROPERTY, searchAndAssertPropertyByName(initialMajorVersionProperties.Items, MAJOR_VERSION_PROPERTY, false), searchAndAssertPropertyByName(secondMajorVersionProperties.Items, MAJOR_VERSION_PROPERTY, false)); deleteAndAssertObject(documentId, true); }
public override void initialize(string testName) { if (arePoliciesAllowed()) { string typeId = getAndAssertPolicyControllableTypeId(); if (null != typeId) { cmisExtensionType extension = new cmisExtensionType(); cmisPropertiesType properties = FileableObject.addPropertyToObject(null, NAME_PROPERTY, FileableObject.generateObjectName(true, "Policy")); FileableObject.addPropertyToObject(properties, TYPE_ID_PROPERTY, getAndAssertPolicyTypeId()); policyId = objectServiceClient.createPolicy(getAndAssertRepositoryId(), properties, getAndAssertRootFolder(), null, null, null, ref extension); } if (null != typeId) { cmisTypeDefinitionType typeDefinition = getAndAssertTypeDefinition(typeId); policyControllableObject = createAndAssertObject(typeDefinition is cmisTypeFolderDefinitionType, getAndAssertRootFolder(), typeId); } else { policyControllableObject = createAndAssertObject(getAndAssertRootFolder(), null); } } }
protected static void assertActualVersioningState(cmisPropertiesType result, System.Nullable<enumVersioningState> versioningState) { if (isValueNotSet(versioningState)) { return; } object propertyCheckedOut = searchAndAssertPropertyByName(result.Items, CHECKED_OUT_PROPERTY, false, false); object propertyVersioningState = searchAndAssertPropertyByName(result.Items, MAJOR_VERSION_PROPERTY, false, false); if (!isVersioningAllowed()) { logger.log("Versioning for Document Type is not allowed!"); Assert.IsTrue(isValueNotSet(propertyCheckedOut) || (!(bool)propertyCheckedOut), ("Invalid Checked Out Property state. Expected: 'undefined' or 'false', actual: '" + propertyCheckedOut + "'")); Assert.IsTrue(isValueNotSet(propertyVersioningState), ("Invalid Versioning State Property. Expected: undefined, actual: " + (((null != propertyVersioningState) && (bool)propertyVersioningState) ? (enumVersioningState.major) : (enumVersioningState.minor)))); } else { if (enumVersioningState.checkedout == versioningState) { Assert.IsTrue(!isValueNotSet(propertyCheckedOut) && (bool)propertyCheckedOut, "Expected Versioning State of Document is Checked Out but Document is not Checked Out"); } else { Assert.IsNotNull(propertyVersioningState, ("Versioning State Property is undefined. Expected Property value: " + versioningState)); enumVersioningState actualState = ((bool)propertyVersioningState) ? (enumVersioningState.major) : (enumVersioningState.minor); Assert.AreEqual(versioningState, actualState, ("Expected Versioning State of Document: " + versioningState + ", actual: " + actualState)); } } }
public FileableObject(enumTypesOfFileableObjects objectType, string objectParentId, string objectTypeId, cmisPropertiesType objectProperties, System.Nullable<enumVersioningState> initialVersion, bool setContentStreamForcibly) : base(objectType, objectParentId, objectTypeId, objectProperties) { this.initialVersion = initialVersion; this.setContentStreamForcibly = setContentStreamForcibly; }
public FileableObject(enumTypesOfFileableObjects objectType, string objectParentId, string objectTypeId, cmisPropertiesType properties, cmisAccessControlListType addACEs, cmisAccessControlListType removeACEs) : base(objectType, objectParentId, objectTypeId, properties) { this.addACEs = addACEs; this.removeACEs = removeACEs; }
protected void assertPropertiesByFilter(cmisPropertiesType properties, string filter) { if (isValueNotSet(filter) || "".Equals(filter) || "*".Equals(filter)) { return; } Assert.IsFalse(isValueNotSet(properties), "Properties are undefined"); Assert.IsFalse(isValueNotSet(properties.Items), "Properties are empty"); string[] tokens = filter.Split(new string[] { ",", ", " }, StringSplitOptions.RemoveEmptyEntries); HashSet<string> trimmedTokens = new HashSet<string>(); foreach (string token in tokens) { trimmedTokens.Add(token.Trim()); } foreach (cmisProperty property in properties.Items) { Assert.IsFalse(isValueNotSet(property), "One of the Properties is in 'not set' state solely"); string name = getPropertyName(property); Assert.IsFalse(isValueNotSet(name), "One of the Properties has no Name Property attribute"); Assert.IsTrue(trimmedTokens.Contains(name), (filter + " filter does not allow " + name + " Property")); } }
private void checkInAndAssertWithExpectedException(string repositoryId, string checkedoutDocumentId, Nullable<bool> major, cmisPropertiesType properties, cmisContentStreamType content, string checkInComment, HashSet<enumServiceException> expectedExceptions, string caseMessage) { try { cmisExtensionType extensions = new cmisExtensionType(); logger.log("[VersioningService->checkIn()]"); // TODO: applyPolicies, addACEs, removeACEs versioningServiceClient.checkIn(repositoryId, ref checkedoutDocumentId, major, properties, content, checkInComment, null, null, null, ref extensions); logger.log("Expected exception during All Versions Receiving with " + caseMessage + " was not thrown"); } catch (FaultException<cmisFaultType> e) { if (expectedExceptions != null && expectedExceptions.Count > 0) { assertException(e, expectedExceptions); } } catch (Exception e) { cancelCheckoutAndDeleteDocumentWithAssertion(checkedoutDocumentId); throw e; } }
private void checkInAndAssertWithExpectedException(string repositoryId, string checkedoutDocumentId, Nullable <bool> major, cmisPropertiesType properties, cmisContentStreamType content, string checkInComment, enumServiceException expectedException, string caseMessage) { HashSet <enumServiceException> expectedExceptions = new HashSet <enumServiceException>(); expectedExceptions.Add(expectedException); checkInAndAssertWithExpectedException(repositoryId, checkedoutDocumentId, major, properties, content, checkInComment, expectedExceptions, caseMessage); }
public CmisObject createObject(bool createPropertiesIfNull, bool reset, string objectParentId, string objectTypeId) { if (reset) { resetObject(); } this.objectTypeId = objectTypeId; objectProperties = getObjectProperties(createPropertiesIfNull); this.objectParentId = objectParentId; return performCreation(); }
public static cmisProperty removePropertyFromObject(cmisPropertiesType properties, string propertyName) { if (isValueNotSet(properties) || isValueNotSet(properties.Items) || isValueNotSet(propertyName) || !PROPERTIES_TYPE_BY_NAME_MAPPING.ContainsKey(propertyName)) { return null; } cmisProperty result = null; for (int i = 0; i < properties.Items.Length; i++) { cmisProperty property = properties.Items[i]; bool propertyIsNull = isValueNotSet(property); if (propertyIsNull || propertyName.Equals(getPropertyName(property))) { if (!propertyIsNull) { result = property; properties.Items[i] = null; } break; } } return result; }
public static cmisPropertiesType addPropertyToObject(cmisPropertiesType properties, string propertyName, object propertyValue) { if ((null == propertyName) || !PROPERTIES_TYPE_BY_NAME_MAPPING.ContainsKey(propertyName)) { return properties; } if (null == properties) { properties = new cmisPropertiesType(); properties.Items = new cmisProperty[2]; } cmisProperty newProperty = null; int elementsAmount = 0; Type propertyType = null; if (!PROPERTIES_TYPE_BY_NAME_MAPPING.TryGetValue(propertyName, out propertyType)) { throw new Exception("Class for " + propertyName + " property was not found"); } foreach (cmisProperty property in properties.Items) { bool propertyNotUndefined = !isValueNotSet(property); if (!propertyNotUndefined || (property.GetType().Equals(propertyType) && propertyName.Equals(getPropertyName(property)))) { if (propertyNotUndefined) { newProperty = property; } break; } elementsAmount++; } newProperty = isValueNotSet(newProperty) ? (createPropertyFromClass(propertyType, propertyName, propertyValue)) : (newProperty); if (properties.Items.Length <= elementsAmount) { cmisProperty[] extendedProperties = properties.Items; Array.Resize(ref extendedProperties, (elementsAmount + 1)); extendedProperties[elementsAmount] = newProperty; properties.Items = extendedProperties; } else { properties.Items[elementsAmount] = newProperty; } return properties; }
// Static methods public static cmisPropertiesType addNamePropertyToObject(cmisPropertiesType properties, string name) { return addPropertyToObject(properties, NAME_PROPERTY, name); }
public CmisObject(enumTypesOfFileableObjects objectType, string objectParentId, string objectTypeId, cmisPropertiesType objectProperties) : this(objectType, objectParentId, objectTypeId) { this.objectProperties = objectProperties; }
private void asserLatestVersionProperties(String objectId, string filter, cmisPropertiesType response, bool major) { Assert.IsFalse(isValueNotSet(response), "Properties holder Object is undefined"); if (isValueNotSet(filter) || "".Equals(filter) || ANY_PROPERTY_FILTER.Equals(filter)) { object actual = searchAndAssertPropertyByName(response.Items, major ? MAJOR_VERSION_PROPERTY : LATEST_VERSION_PROPERTY, false); Assert.IsTrue(((null != actual) && (bool)actual), (objectId + " Object is not Latest Version Object")); assertActualVersioningState(response, (major) ? (enumVersioningState.major) : (enumVersioningState.minor)); } else { assertPropertiesByFilter(response, filter); } }
protected string updatePropertiesUsingCredentials(string objectId, string username, string password) { string changeToken = ""; cmisExtensionType extension = new cmisExtensionType(); cmisPropertiesType objectProperties = new cmisPropertiesType(); objectProperties.Items = new cmisProperty[1]; objectProperties.Items[0] = new cmisPropertyString(); objectProperties.Items[0].propertyDefinitionId = NAME_PROPERTY; ((cmisPropertyString)objectProperties.Items[0]).value = new string[] { FileableObject.generateObjectName(false, "_renamed") }; logger.log("[ObjectService->updateProperties]"); objectServiceClient.updateProperties(repositoryId, ref objectId, ref changeToken, objectProperties, ref extension); Assert.IsNotNull(objectId, "Returned objectId is null"); return objectId; }
private static cmisProperty searchForProperty(cmisPropertiesType properties, string propertyName) { if ((null != properties) && (null != properties.Items) && (properties.Items.Length > 0) && (null != propertyName) && !"".Equals(propertyName)) { foreach (cmisProperty property in properties.Items) { string name = getPropertyName(property); if ((null != name) && name.Equals(propertyName)) { return property; } } } return null; }
private void checkInAndAssertWithExpectedException(string repositoryId, string checkedoutDocumentId, Nullable<bool> major, cmisPropertiesType properties, cmisContentStreamType content, string checkInComment, enumServiceException expectedException, string caseMessage) { HashSet<enumServiceException> expectedExceptions = new HashSet<enumServiceException>(); expectedExceptions.Add(expectedException); checkInAndAssertWithExpectedException(repositoryId, checkedoutDocumentId, major, properties, content, checkInComment, expectedExceptions, caseMessage); }
private void checkInAndAssertWithExpectedException(string repositoryId, string checkedoutDocumentId, Nullable <bool> major, cmisPropertiesType properties, cmisContentStreamType content, string checkInComment, HashSet <enumServiceException> expectedExceptions, string caseMessage) { try { cmisExtensionType extensions = new cmisExtensionType(); logger.log("[VersioningService->checkIn()]"); // TODO: applyPolicies, addACEs, removeACEs versioningServiceClient.checkIn(repositoryId, ref checkedoutDocumentId, major, properties, content, checkInComment, null, null, null, ref extensions); logger.log("Expected exception during All Versions Receiving with " + caseMessage + " was not thrown"); } catch (FaultException <cmisFaultType> e) { if (expectedExceptions != null && expectedExceptions.Count > 0) { assertException(e, expectedExceptions); } } catch (Exception e) { cancelCheckoutAndDeleteDocumentWithAssertion(checkedoutDocumentId); throw e; } }
// TODO: <Array> policies // <Array> ACE addACEs // <Array> ACE removeACEs public FileableObject(enumTypesOfFileableObjects objectType, string objectParentId, string objectTypeId, cmisPropertiesType properties) : base(objectType, objectParentId, objectTypeId, properties) { }
public virtual cmisPropertiesType getObjectProperties(bool createIfNull) { if ((null == objectProperties) && createIfNull) { objectProperties = new cmisPropertiesType(); addProperty(TYPE_ID_PROPERTY, ObjectTypeId); } if (!isValueNotSet(objectProperties) && (properties.Count > 0)) { if (isValueNotSet(objectProperties.Items)) { objectProperties.Items = new cmisProperty[properties.Values.Count]; } else { if (objectProperties.Items.Length != properties.Values.Count) { cmisProperty[] newProperties = null; Array.Resize(ref newProperties, properties.Values.Count); objectProperties.Items = newProperties; } } properties.Values.CopyTo(objectProperties.Items, 0); } return objectProperties; }
protected static void assertProperties(FileableObject expectedProperties, cmisPropertiesType properties) { cmisObjectType cmisObject = new cmisObjectType(); cmisObject.properties = properties; assertObject(expectedProperties, cmisObject, false, enumIncludeRelationships.none); }
public static cmisPropertiesType ToCmisPropertiesType(TextContent textContent, IEnumerable <Category> categories) { var properties = new cmisPropertiesType(); var items = new List <cmisProperty>(); items.Add(new cmisPropertyId() { localName = CmisPropertyDefinitionId.BaseTypeId, propertyDefinitionId = CmisPropertyDefinitionId.BaseTypeId, value = new string[] { "cmis:document" } }); items.Add(new cmisPropertyId() { localName = "UserId", propertyDefinitionId = CmisPropertyDefinitionId.CreatedBy, value = new string[] { textContent.UserId } }); items.Add(new cmisPropertyDateTime() { localName = "UtcCreationDate", propertyDefinitionId = CmisPropertyDefinitionId.CreationDate, value = new[] { textContent.UtcCreationDate } }); items.Add(new cmisPropertyDateTime() { localName = "UtcLastModificationDate", propertyDefinitionId = CmisPropertyDefinitionId.LastModificationDate, value = new[] { textContent.UtcLastModificationDate } }); items.Add(new cmisPropertyString() { localName = "UserKey", propertyDefinitionId = CmisPropertyDefinitionId.Name, value = new[] { textContent.UserKey } }); items.Add(new cmisPropertyId() { localName = "IntegrateId", propertyDefinitionId = CmisPropertyDefinitionId.ObjectId, value = new[] { textContent.IntegrateId } }); items.Add(new cmisPropertyId() { localName = "SchemaName", propertyDefinitionId = CmisPropertyDefinitionId.ObjectTypeId, value = new[] { textContent.SchemaName } }); items.Add(new cmisPropertyString() { localName = "ParentUUID", propertyDefinitionId = CmisPropertyDefinitionId.ParentId, value = new[] { textContent.ParentUUID } }); var categoriesString = ToCategoriesString(categories); items.Add(new cmisPropertyString() { localName = "___Categories___", propertyDefinitionId = CmisPropertyDefinitionId.ParentId, value = new[] { categoriesString } }); var mediaValues = new List <string>(); var mediaPathField = Kooboo.CMS.Common.Runtime.EngineContext.Current.Resolve <IMediaPathField>(); foreach (var item in textContent) { if (!item.Key.StartsWith("__")) { items.Add(ToCmisProperty(item)); if (item.Value is string && mediaPathField.IsMediaPathField(item.Value.ToString())) { mediaValues.Add(item.Value.ToString()); } } } if (mediaValues.Count > 0) { var mediaBinaryString = mediaPathField.ToBinaryString(mediaValues.ToArray()); items.Add(new cmisPropertyString() { localName = "_____MediaBinaryString_____", propertyDefinitionId = "_____MediaBinaryString_____", value = new[] { mediaBinaryString } }); } properties.Items = items.ToArray(); return(properties); }
protected virtual void resetObject() { objectId = null; objectTypeId = null; objectParentId = null; objectProperties = null; properties.Clear(); }