public IList <IDictionary <string, object> > RepositorySearchForPolId(IDictionary <string, string> properties, IList <DateRange> dateRanges = null, ObjectStore objectStore = P8ContentEngine.DefaultObjectStore, DocumentClass documentClass = P8ContentEngine.DefaultDocumentClass, bool adminOverride = false) { var whereClause = string.Concat(properties.Aggregate ( string.Empty, (current, pt) => string.Concat ( current, string.Format ( " AND '{1}' IN dc1.[{0}] ", pt.Key, pt.Value.Replace("'", "''") ) ) ), BuildDateRangeSQL(dateRanges)); var repositorySearch = new RepositorySearch { SearchScope = new ObjectStoreScope { objectStore = objectStore.GetDescription() }, SearchSQL = string.Format( @"SELECT TOP 500 * FROM {0} dc1 WHERE {1}", documentClass.GetDescription(), Regex.Replace(whereClause, @"^\s+AND\s+?", string.Empty, RegexOptions.IgnoreCase)) }; var searchResult = Search(repositorySearch, adminOverride); var repositoryResults = new List <IDictionary <string, object> >(); if (searchResult != null && searchResult.Object != null) { repositoryResults.AddRange ( searchResult.Object.Select ( o => o.Property.ToDictionary <PropertyType, string, object> ( p => p.propertyId, Utilities.GetPropertyValue ) ) ); } return(repositoryResults); }
public IEnumerable <SingleObjectResponse> GetDocumentObject(Guid id, IList <string> excludeProperties = null, IList <string> includeProperties = null, ObjectStore objectStore = DefaultObjectStore, DocumentClass documentClass = DefaultDocumentClass) { var documentInfoRequest = new[] { new ObjectRequestType { SourceSpecification = new ObjectSpecification { objectStore = objectStore.GetDescription(), classId = documentClass.GetDescription(), objectId = id.ToString(DefaultIDFormat) }, PropertyFilter = new PropertyFilterType { maxRecursion = 2, maxRecursionSpecified = true } } }; if (excludeProperties != null && excludeProperties.Any()) { documentInfoRequest.First().PropertyFilter.ExcludeProperties = excludeProperties.ToArray(); } if (includeProperties != null && includeProperties.Any()) { documentInfoRequest.First().PropertyFilter.IncludeProperties = (from ip in includeProperties select new FilterElementType { Value = ip }).ToArray(); } return(GetObjects(documentInfoRequest).OfType <SingleObjectResponse>().ToList()); }
public IList <IDictionary <string, object> > RepositorySearch(IDictionary <string, string> properties, IList <DateRange> dateRanges = null, ObjectStore objectStore = P8ContentEngine.DefaultObjectStore, DocumentClass documentClass = P8ContentEngine.DefaultDocumentClass, bool adminOverride = false) { var whereClause = string.Concat(properties.Aggregate ( string.Empty, (current, pt) => { string strRet = ""; if (pt.Key == "WorkflowGUID") { strRet += string.Concat ( current, string.Format ( " AND dc1.[{0}] = '{1}'", pt.Key, pt.Value.Replace("'", "''") ) ); } else { strRet += string.Concat ( current, string.Format ( " AND dc1.[{0}] LIKE '%{1}%'", pt.Key, pt.Value.Replace("'", "''") ) ); } return(strRet); } ), BuildDateRangeSQL(dateRanges)); var repositorySearch = new RepositorySearch { SearchScope = new ObjectStoreScope { objectStore = objectStore.GetDescription() }, SearchSQL = string.Format( @"SELECT TOP 500 * FROM {0} dc1 WHERE {1}", documentClass.GetDescription(), Regex.Replace(whereClause, @"^\s+AND\s+?", string.Empty, RegexOptions.IgnoreCase)) }; // var repositorySearch = new RepositorySearch // { // SearchScope = new ObjectStoreScope // { // objectStore = objectStore.GetDescription() // }, // SearchSQL = string.Format( // @"SELECT TOP 500 dc1.* // FROM {0} dc1 RIGHT OUTER JOIN {0} dc2 ON dc1.ID = dc2.ID // WHERE ({1}) // OR (dc1.ID = dc2.RelatedDocumentID OR dc1.RelatedDocumentID = dc2.RelatedDocumentID) // OPTIONS (FULLTEXTROWLIMIT 500)", // documentClass.GetDescription(), // Regex.Replace(whereClause, @"^\s+AND\s+?", string.Empty, RegexOptions.IgnoreCase)) // }; var searchResult = Search(repositorySearch, adminOverride); var repositoryResults = new List <IDictionary <string, object> >(); if (searchResult != null && searchResult.Object != null) { repositoryResults.AddRange ( searchResult.Object.Select ( o => o.Property.ToDictionary <PropertyType, string, object> ( p => p.propertyId, Utilities.GetPropertyValue ) ) ); } return(repositoryResults); }
public IList <IDictionary <string, object> > ContentSearch(string keywords, IDictionary <string, string> properties = null, IList <DateRange> dateRanges = null, ObjectStore objectStore = P8ContentEngine.DefaultObjectStore, DocumentClass documentClass = P8ContentEngine.DefaultDocumentClass, bool adminOverride = false) { var whereClause = string.Concat(properties != null ? Regex.Replace(properties.Aggregate ( string.Empty, (current, pt) => string.Concat ( current, string.Format ( " AND dc1.[{0}] LIKE '%{1}%'", pt.Key, pt.Value.Replace("'", "''") ) ) ), @"^\s+AND\s+?", string.Empty, RegexOptions.IgnoreCase) : string.Empty, BuildDateRangeSQL(dateRanges)); var contentSearch = new RepositorySearch { SearchScope = new ObjectStoreScope { objectStore = objectStore.GetDescription() }, SearchSQL = string.Format( @"SELECT TOP 500 cs.*, dc1.* FROM {0} dc1 INNER JOIN ContentSearch cs ON dc1.This = cs.QueriedObject WHERE CONTAINS(dc1.*, '{1}') {2} ORDER BY cs.Rank DESC OPTIONS (FULLTEXTROWLIMIT 500)" , documentClass.GetDescription(), keywords.Replace("'", "''"), !string.IsNullOrEmpty(whereClause) ? string.Format("AND ({0})", whereClause) : string.Empty) }; // var contentSearch = new RepositorySearch // { // SearchScope = new ObjectStoreScope // { // objectStore = objectStore.GetDescription() // }, // SearchSQL = string.Format( // @"SELECT TOP 500 * // FROM ({0} dc1 INNER JOIN ContentSearch cs ON dc1.This = cs.QueriedObject) // RIGHT OUTER JOIN {0} dc2 ON dc1.ID = dc2.ID // WHERE CONTAINS(dc1.*, '{1}') // AND ({2}) // OR (dc1.ID = dc2.RelatedDocumentID OR dc1.RelatedDocumentID = dc2.RelatedDocumentID) // ORDER BY cs.Rank DESC // OPTIONS (FULLTEXTROWLIMIT 500)", // documentClass.GetDescription(), // keywords.Replace("'", "''"), // Regex.Replace(whereClause, @"^\s+AND\s+?", string.Empty, RegexOptions.IgnoreCase)) // }; var searchResults = Search(contentSearch, adminOverride); var contentResults = new List <IDictionary <string, object> >(); if (searchResults != null && searchResults.Object != null) { foreach (var searchResult in searchResults.Object) { var dmsProperties = new Dictionary <string, object>(); foreach (var dmsProperty in searchResult.Property .Where ( p => !dmsProperties.ContainsKey(p.propertyId) )) { dmsProperties.Add(dmsProperty.propertyId, Utilities.GetPropertyValue(dmsProperty)); } contentResults.Add(dmsProperties); } } return(contentResults); }
public bool AllowDocumentAccess(Guid id, IList <string> allowUsers, ObjectStore objectStore = DefaultObjectStore, DocumentClass documentClass = DefaultDocumentClass) { var accessProperties = new List <DependentObjectType>(); if (allowUsers != null) { accessProperties.AddRange(allowUsers.Select(allowUser => new DependentObjectType { classId = "AccessPermission", dependentAction = DependentObjectTypeDependentAction.Insert, dependentActionSpecified = true, Property = new PropertyType[] { new SingletonString { propertyId = "GranteeName", Value = allowUser }, new SingletonInteger32 { propertyId = "AccessType", Value = (int)AccessType.Allow, ValueSpecified = true }, new SingletonInteger32 { propertyId = "AccessMask", Value = (int)AccessLevel.WriteDocument, ValueSpecified = true }, new SingletonInteger32 { propertyId = "InheritableDepth", Value = 0, ValueSpecified = true } } }).ToList()); } var actionProperties = new List <ModifiablePropertyType> { new ListOfObject { propertyId = "Permissions", Value = accessProperties.ToArray() } }; var updateRequest = new ExecuteChangesRequest { ChangeRequest = new[] { new ChangeRequestType { id = "1", Action = new ActionType[] { new UpdateAction() }, ActionProperties = actionProperties.ToArray(), TargetSpecification = new ObjectSpecification { objectStore = objectStore.GetDescription(), classId = documentClass.GetDescription(), objectId = id.ToString(P8ContentEngine.DefaultIDFormat) } } }, refresh = true, refreshSpecified = true }; return(Execute(updateRequest, true).Length > 0); }
public IList <IDictionary <string, object> > RetrieveDocumentAccess(Guid id, ObjectStore objectStore = DefaultObjectStore, DocumentClass documentClass = DefaultDocumentClass) { var accessInfoRequest = new[] { new ObjectRequestType { SourceSpecification = new ObjectSpecification { objectStore = objectStore.GetDescription(), classId = documentClass.GetDescription(), objectId = id.ToString(DefaultIDFormat) }, PropertyFilter = new PropertyFilterType { maxRecursion = 1, maxRecursionSpecified = true, IncludeProperties = new[] { new FilterElementType { Value = "Permissions" }, new FilterElementType { Value = "AccessPermission" }, new FilterElementType { Value = "AccessMask" }, new FilterElementType { Value = "AccessType" }, new FilterElementType { Value = "GranteeName" }, new FilterElementType { Value = "GranteeType" }, new FilterElementType { Value = "InheritableDepth" }, new FilterElementType { Value = "PermissionSource" } } } } }; var accessInfoResponse = GetObjects(accessInfoRequest); var permissionsList = accessInfoResponse.OfType <SingleObjectResponse>() .SelectMany(o => o.Object.Property) .Where(p => p.propertyId == "Permissions") .Select(p => p as ListOfObject); var accessPermissions = new List <IDictionary <string, object> >(); foreach (var permission in permissionsList.SelectMany(o => o.Value)) { dynamic accessPermission = new ExpandoObject(); foreach (var property in permission.Property) { switch (property.propertyId) { case "AccessMask": accessPermission.AccessMask = ((SingletonInteger32)property).Value; break; case "AccessType": accessPermission.AccessType = ((SingletonInteger32)property).Value; break; case "GranteeName": accessPermission.GranteeName = ((SingletonString)property).Value; break; case "GranteeType": accessPermission.GranteeType = ((SingletonInteger32)property).Value; break; case "InheritableDepth": accessPermission.InheritableDepth = ((SingletonInteger32)property).Value; break; case "PermissionSource": accessPermission.PermissionSource = ((SingletonInteger32)property).Value; break; default: continue; } } accessPermissions.Add(accessPermission); } return(accessPermissions); }
public bool RemoveDocumentAccess(Guid id, IList <string> removeUsers, ObjectStore objectStore = DefaultObjectStore, DocumentClass documentClass = DefaultDocumentClass) { var permissionsList = RetrieveDocumentAccess(id, objectStore, documentClass); var accessPermissions = removeUsers.Select ( u => permissionsList.FirstOrDefault ( kvp => kvp["GranteeName"].ToString().Equals(u, StringComparison.CurrentCultureIgnoreCase) ) ).Select(permissionsList.IndexOf).Where(i => i >= 0).Select ( userIndex => new DependentObjectType { classId = "AccessPermission", dependentAction = DependentObjectTypeDependentAction.Delete, dependentActionSpecified = true, originalIndex = userIndex, originalIndexSpecified = true } ).ToArray(); if (accessPermissions.Length == 0) { return(true); } var actionProperties = new List <ModifiablePropertyType> { new ListOfObject { propertyId = "Permissions", Value = accessPermissions } }; var updateRequest = new ExecuteChangesRequest { ChangeRequest = new[] { new ChangeRequestType { id = "1", Action = new ActionType[] { new UpdateAction() }, ActionProperties = actionProperties.ToArray(), TargetSpecification = new ObjectSpecification { objectStore = objectStore.GetDescription(), classId = documentClass.GetDescription(), objectId = id.ToString(DefaultIDFormat) } } }, refresh = true, refreshSpecified = true }; return(Execute(updateRequest, true).Length > 0); }
public Guid?CreateDocument(string name, byte[] content, IDictionary <string, object> properties = null, ObjectStore objectStore = P8ContentEngine.DefaultObjectStore, DocumentClass documentClass = P8ContentEngine.DefaultDocumentClass) { if (name == string.Empty) { throw new ArgumentException(nameof(name)); } if (name == null) { throw new ArgumentNullException(nameof(name)); } if (content == null) { throw new ArgumentNullException(nameof(content)); } properties = ResolveTitleAndMimeType(name, properties); var mimeType = properties.ContainsKey(MIME_TYPE) ? properties[MIME_TYPE] as string : MimeTypeUtility.DefaultType; var actionProperties = new List <ModifiablePropertyType> { new ListOfObject { propertyId = "ContentElements", Value = new[] { new DependentObjectType { classId = "ContentTransfer", dependentAction = DependentObjectTypeDependentAction.Insert, dependentActionSpecified = true, Property = new PropertyType[] { new SingletonString { propertyId = "ContentType", Value = mimeType }, new SingletonString { propertyId = "RetrievalName", Value = name }, new ContentData { propertyId = "Content", Value = new InlineContent { Binary = content } } } } } } }; if (properties != null) { actionProperties.AddRange(Utilities.GetPropertyCollection(properties)); } var executeRequest = new ExecuteChangesRequest { ChangeRequest = new[] { new ChangeRequestType { id = "1", Action = new ActionType[] { new CreateAction { classId = documentClass.GetDescription() }, new CheckinAction { autoClassify = true, autoClassifySpecified = true, checkinMinorVersion = true, checkinMinorVersionSpecified = true }, new PromoteVersionAction() }, ActionProperties = actionProperties.ToArray(), TargetSpecification = new ObjectReference { classId = "ObjectStore", objectStore = objectStore.GetDescription() } } }, refresh = true, refreshSpecified = true }; var createResults = Execute(executeRequest, "ID"); var id = (from cr in createResults.FirstOrDefault() where cr.Key.Equals("ID", StringComparison.CurrentCultureIgnoreCase) select cr.Value).FirstOrDefault(); if (id != null) { return(new Guid(id.ToString())); } return(null); }
public bool DeleteDocument(Guid id, bool allVersions, ObjectStore objectStore = DefaultObjectStore, DocumentClass documentClass = DefaultDocumentClass) { if (allVersions) { var deleteInfoRequest = new[] { new ObjectRequestType { SourceSpecification = new ObjectSpecification { objectStore = objectStore.GetDescription(), classId = documentClass.GetDescription(), objectId = id.ToString(DefaultIDFormat) }, PropertyFilter = new PropertyFilterType { maxRecursion = 1, maxRecursionSpecified = true, IncludeProperties = new[] { new FilterElementType { Value = "VersionSeries" } } } } }; var deleteInfoResponse = GetObjects(deleteInfoRequest); var series = (from responseProperty in (((SingleObjectResponse)deleteInfoResponse[0]).Object).Property where responseProperty.propertyId == "VersionSeries" select((SingletonObject)responseProperty).Value as ObjectValue).FirstOrDefault(); if (series != null) { id = new Guid(series.objectId); } else { throw new ApplicationException(string.Format("Could not retrieve the version series for {0}", id.ToString(P8ContentEngine.DefaultIDFormat))); } } var deleteRequest = new ExecuteChangesRequest { ChangeRequest = new[] { new ChangeRequestType { id = "1", Action = new ActionType[] { new DeleteAction() }, TargetSpecification = new ObjectSpecification { objectStore = objectStore.GetDescription(), classId = (allVersions) ? "VersionSeries" : documentClass.GetDescription(), objectId = id.ToString(P8ContentEngine.DefaultIDFormat) } } }, refresh = true, refreshSpecified = true }; var deleteResult = Execute(deleteRequest); return((deleteResult.Length > 0) && deleteResult[0].id == "1"); }
public bool CheckinDocument(Guid id, ObjectStore objectStore = DefaultObjectStore, DocumentClass documentClass = DefaultDocumentClass) { var checkinInfoRequest = new[] { new ObjectRequestType { SourceSpecification = new ObjectSpecification { objectStore = objectStore.GetDescription(), classId = documentClass.GetDescription(), objectId = id.ToString(DefaultIDFormat) }, PropertyFilter = new PropertyFilterType { maxRecursion = 1, maxRecursionSpecified = true, IncludeProperties = new[] { new FilterElementType { Value = "Reservation" } } } } }; var checkinInfoResponse = GetObjects(checkinInfoRequest); var reservation = (from responseProperty in (((SingleObjectResponse)checkinInfoResponse[0]).Object).Property where responseProperty.propertyId == "Reservation" select((SingletonObject)responseProperty).Value as ObjectValue).FirstOrDefault(); if (reservation != null) { id = new Guid(reservation.objectId); } var checkinRequest = new ExecuteChangesRequest { ChangeRequest = new[] { new ChangeRequestType { id = "1", Action = new ActionType[] { new CheckinAction { autoClassify = true, autoClassifySpecified = true, checkinMinorVersion = true, checkinMinorVersionSpecified = true }, new PromoteVersionAction() }, TargetSpecification = new ObjectReference { objectStore = objectStore.GetDescription(), classId = documentClass.GetDescription(), objectId = id.ToString(DefaultIDFormat) }, RefreshFilter = new PropertyFilterType { maxRecursion = 1, maxRecursionSpecified = true, IncludeProperties = new[] { new FilterElementType { Value = "VersionStatus" } } } } }, refresh = true, refreshSpecified = true }; var checkinResponse = Execute(checkinRequest); var versionStatus = (from responseProperty in checkinResponse[0].Property where responseProperty.propertyId == "VersionStatus" select responseProperty as SingletonInteger32).FirstOrDefault(); return(versionStatus != null && versionStatus.Value == (int)VersionStatus.Released); }
public Guid?CheckoutDocument(Guid id, ObjectStore objectStore = DefaultObjectStore, DocumentClass documentClass = DefaultDocumentClass) { var checkoutInfoRequest = new[] { new ObjectRequestType { SourceSpecification = new ObjectSpecification { objectStore = objectStore.GetDescription(), classId = documentClass.GetDescription(), objectId = id.ToString(DefaultIDFormat) }, PropertyFilter = new PropertyFilterType { maxRecursion = 1, maxRecursionSpecified = true, IncludeProperties = new[] { new FilterElementType { Value = "CurrentVersion" }, new FilterElementType { Value = "Reservation" } } } } }; var checkoutInfoResponse = GetObjects(checkoutInfoRequest); var reservation = (from responseProperty in (((SingleObjectResponse)checkoutInfoResponse[0]).Object).Property where responseProperty.propertyId == "Reservation" select((SingletonObject)responseProperty).Value as ObjectValue).FirstOrDefault(); if (reservation != null) { return(new Guid(reservation.objectId)); } var currentVersion = (from responseProperty in (((SingleObjectResponse)checkoutInfoResponse[0]).Object).Property where responseProperty.propertyId == "CurrentVersion" select((SingletonObject)responseProperty).Value as ObjectValue).FirstOrDefault(); if (currentVersion != null) { id = new Guid(currentVersion.objectId); } var executeRequest = new ExecuteChangesRequest { ChangeRequest = new[] { new ChangeRequestType { id = "1", Action = new ActionType[] { new CheckoutAction { reservationType = ReservationType.Exclusive, reservationTypeSpecified = true } }, TargetSpecification = new ObjectReference { objectStore = objectStore.GetDescription(), classId = documentClass.GetDescription(), objectId = id.ToString(DefaultIDFormat) }, RefreshFilter = new PropertyFilterType { maxRecursion = 1, maxRecursionSpecified = true, IncludeProperties = new[] { new FilterElementType { Value = "Reservation" } } } } }, refresh = true, refreshSpecified = true }; var checkoutResponse = Execute(executeRequest); reservation = (from responseProperty in checkoutResponse[0].Property where responseProperty.propertyId == "Reservation" select((SingletonObject)responseProperty).Value as ObjectValue).FirstOrDefault(); if (reservation != null) { return(new Guid(reservation.objectId)); } return(null); }
public IList <byte[]> GetDocumentContent(Guid id, IEnumerable <SingleObjectResponse> documentObject = null, ObjectStore objectStore = DefaultObjectStore, DocumentClass documentClass = DefaultDocumentClass) { var inlineContents = new List <byte[]>(); var documentInfoResponse = documentObject ?? GetDocumentObject(id, null, null, objectStore, documentClass); var contentElements = documentInfoResponse.SelectMany ( o => o.Object.Property.OfType <ListOfObject>().Where ( p => p.propertyId.Equals("ContentElements", StringComparison.CurrentCultureIgnoreCase) ) ).ToList(); foreach (var contentElement in contentElements.Where(ce => ce.Value != null)) { for (var contentIter = 0; contentIter < contentElement.Value.Length; contentIter++) { var contentRequest = new[] { new ContentRequestType { id = "1", cacheAllowed = true, cacheAllowedSpecified = true, maxBytes = 1024 * 1024, maxBytesSpecified = false, startOffset = 0, startOffsetSpecified = true, continueFrom = null, ElementSpecification = new ElementSpecificationType { itemIndex = contentIter, itemIndexSpecified = true, elementSequenceNumber = 0, elementSequenceNumberSpecified = false }, SourceSpecification = new ObjectSpecification { objectStore = objectStore.GetDescription(), classId = documentClass.GetDescription(), objectId = id.ToString(DefaultIDFormat) } } }; var contentResponse = GetContents(contentRequest); inlineContents.AddRange ( contentResponse.OfType <ContentElementResponse>().Select ( o => ((InlineContent)o.Content).Binary ).ToList() ); } } return(inlineContents); }
public bool UpdateDocument(Guid id, string name, byte[] content, IDictionary <string, object> properties = null, ObjectStore objectStore = DefaultObjectStore, DocumentClass documentClass = DefaultDocumentClass) { var updateContent = name != null && content != null; var updateProperties = properties != null && properties.Count > 0; if (!updateContent && !updateProperties) { throw new ArgumentException("Insufficient arguments provided (name, content and/or properties)"); } properties = ResolveTitleAndMimeType(name, properties); var mimeType = properties.ContainsKey(MIME_TYPE) ? properties[MIME_TYPE] as string : MimeTypeUtility.DefaultType; var reservationID = updateContent ? CheckoutDocument(id, objectStore, documentClass) : Guid.Empty; if (reservationID != null && reservationID != Guid.Empty) { id = reservationID.Value; } var actionProperties = new List <ModifiablePropertyType>(); if (updateContent) { actionProperties.Add(new ListOfObject { propertyId = "ContentElements", Value = new[] { new DependentObjectType { classId = "ContentTransfer", dependentAction = DependentObjectTypeDependentAction.Insert, dependentActionSpecified = true, Property = new PropertyType[] { new SingletonString { propertyId = "ContentType", Value = mimeType }, new ContentData { propertyId = "Content", Value = new InlineContent { Binary = content } } } } } }); } if (updateProperties) { actionProperties.AddRange(Utilities.GetPropertyCollection(properties)); } var updateRequest = new ExecuteChangesRequest { ChangeRequest = new[] { new ChangeRequestType { id = "1", Action = new ActionType[] { new UpdateAction() }, ActionProperties = actionProperties.ToArray(), TargetSpecification = new ObjectSpecification { objectStore = objectStore.GetDescription(), classId = documentClass.GetDescription(), objectId = id.ToString(DefaultIDFormat) } } }, refresh = true, refreshSpecified = true }; Execute(updateRequest); return((!updateContent) || CheckinDocument(id, objectStore, documentClass)); }