This project has retired. For details please refer to its Attic page.
TransientFolderImpl xref

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.chemistry.opencmis.client.runtime;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  import java.util.Map;
24  
25  import org.apache.chemistry.opencmis.client.api.CmisObject;
26  import org.apache.chemistry.opencmis.client.api.Document;
27  import org.apache.chemistry.opencmis.client.api.FileableCmisObject;
28  import org.apache.chemistry.opencmis.client.api.Folder;
29  import org.apache.chemistry.opencmis.client.api.ItemIterable;
30  import org.apache.chemistry.opencmis.client.api.ObjectId;
31  import org.apache.chemistry.opencmis.client.api.ObjectType;
32  import org.apache.chemistry.opencmis.client.api.OperationContext;
33  import org.apache.chemistry.opencmis.client.api.Policy;
34  import org.apache.chemistry.opencmis.client.api.Session;
35  import org.apache.chemistry.opencmis.client.api.TransientFolder;
36  import org.apache.chemistry.opencmis.client.api.Tree;
37  import org.apache.chemistry.opencmis.commons.PropertyIds;
38  import org.apache.chemistry.opencmis.commons.data.Ace;
39  import org.apache.chemistry.opencmis.commons.data.ContentStream;
40  import org.apache.chemistry.opencmis.commons.data.FailedToDeleteData;
41  import org.apache.chemistry.opencmis.commons.enums.UnfileObject;
42  import org.apache.chemistry.opencmis.commons.enums.VersioningState;
43  import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
44  
45  public class TransientFolderImpl extends AbstractTransientFileableCmisObject implements TransientFolder {
46  
47      private boolean isMarkedForDeleteTree;
48      private boolean deleteTreeAllVersions;
49      private UnfileObject deleteTreeUnfile;
50      private boolean deleteTreeContinueOnFailure;
51  
52      @Override
53      protected void initialize(Session session, CmisObject object) {
54          super.initialize(session, object);
55  
56          isMarkedForDeleteTree = false;
57      }
58  
59      public Document createDocument(Map<String, ?> properties, ContentStream contentStream,
60              VersioningState versioningState, List<Policy> policies, List<Ace> addAces, List<Ace> removeAces,
61              OperationContext context) {
62          return ((Folder) getCmisObject()).createDocument(properties, contentStream, versioningState, policies, addAces,
63                  removeAces, context);
64      }
65  
66      public Document createDocument(Map<String, ?> properties, ContentStream contentStream,
67              VersioningState versioningState) {
68          return ((Folder) getCmisObject()).createDocument(properties, contentStream, versioningState);
69      }
70  
71      public Document createDocumentFromSource(ObjectId source, Map<String, ?> properties,
72              VersioningState versioningState, List<Policy> policies, List<Ace> addAces, List<Ace> removeAces,
73              OperationContext context) {
74          return ((Folder) getCmisObject()).createDocumentFromSource(source, properties, versioningState, policies,
75                  addAces, removeAces, context);
76      }
77  
78      public Document createDocumentFromSource(ObjectId source, Map<String, ?> properties, VersioningState versioningState) {
79          return ((Folder) getCmisObject()).createDocumentFromSource(source, properties, versioningState);
80      }
81  
82      public Folder createFolder(Map<String, ?> properties, List<Policy> policies, List<Ace> addAces,
83              List<Ace> removeAces, OperationContext context) {
84          return ((Folder) getCmisObject()).createFolder(properties, policies, addAces, removeAces, context);
85      }
86  
87      public Folder createFolder(Map<String, ?> properties) {
88          return ((Folder) getCmisObject()).createFolder(properties);
89      }
90  
91      public Policy createPolicy(Map<String, ?> properties, List<Policy> policies, List<Ace> addAces,
92              List<Ace> removeAces, OperationContext context) {
93          return ((Folder) getCmisObject()).createPolicy(properties, policies, addAces, removeAces, context);
94      }
95  
96      public Policy createPolicy(Map<String, ?> properties) {
97          return ((Folder) getCmisObject()).createPolicy(properties);
98      }
99  
100     public void deleteTree(boolean allversions, UnfileObject unfile, boolean continueOnFailure) {
101         deleteTreeAllVersions = allversions;
102         deleteTreeUnfile = unfile;
103         deleteTreeContinueOnFailure = continueOnFailure;
104 
105         isMarkedForDeleteTree = true;
106         isMarkedForDelete = true;
107         isModified = true;
108     }
109 
110     public List<Tree<FileableCmisObject>> getFolderTree(int depth) {
111         return ((Folder) getCmisObject()).getFolderTree(depth);
112     }
113 
114     public List<Tree<FileableCmisObject>> getFolderTree(int depth, OperationContext context) {
115         return ((Folder) getCmisObject()).getFolderTree(depth, context);
116     }
117 
118     public List<Tree<FileableCmisObject>> getDescendants(int depth) {
119         return ((Folder) getCmisObject()).getDescendants(depth);
120     }
121 
122     public List<Tree<FileableCmisObject>> getDescendants(int depth, OperationContext context) {
123         return ((Folder) getCmisObject()).getDescendants(depth, context);
124     }
125 
126     public ItemIterable<CmisObject> getChildren() {
127         return ((Folder) getCmisObject()).getChildren();
128     }
129 
130     public ItemIterable<CmisObject> getChildren(OperationContext context) {
131         return ((Folder) getCmisObject()).getChildren(context);
132     }
133 
134     public boolean isRootFolder() {
135         return ((Folder) getCmisObject()).isRootFolder();
136     }
137 
138     public Folder getFolderParent() {
139         return ((Folder) getCmisObject()).getFolderParent();
140     }
141 
142     public String getPath() {
143         return ((Folder) getCmisObject()).getPath();
144     }
145 
146     public ItemIterable<Document> getCheckedOutDocs() {
147         return ((Folder) getCmisObject()).getCheckedOutDocs();
148     }
149 
150     public ItemIterable<Document> getCheckedOutDocs(OperationContext context) {
151         return ((Folder) getCmisObject()).getCheckedOutDocs();
152     }
153 
154     public String getParentId() {
155         return getPropertyValue(PropertyIds.PARENT_ID);
156     }
157 
158     public List<ObjectType> getAllowedChildObjectTypes() {
159         List<ObjectType> result = new ArrayList<ObjectType>();
160 
161         List<String> otids = getPropertyValue(PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS);
162         if (otids == null) {
163             return result;
164         }
165 
166         for (String otid : otids) {
167             result.add(getSession().getTypeDefinition(otid));
168         }
169 
170         return result;
171     }
172 
173     public void setAllowedChildObjectTypes(List<ObjectType> types) {
174         List<String> typeIds = new ArrayList<String>();
175 
176         if ((types != null) && (!types.isEmpty())) {
177             for (ObjectType type : types) {
178                 if (type != null) {
179                     typeIds.add(type.getId());
180                 }
181             }
182         }
183 
184         setPropertyValue(PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS, typeIds);
185     }
186 
187     // override save()
188 
189     @Override
190     public ObjectId save() {
191         if (!isModified()) {
192             // nothing has change, so there is nothing to do
193             return getObjectId();
194         }
195 
196         if (isMarkedForDeleteTree) {
197             FailedToDeleteData ftd = getBinding().getObjectService().deleteTree(getRepositoryId(), getId(),
198                     deleteTreeAllVersions, deleteTreeUnfile, deleteTreeContinueOnFailure, null);
199 
200             if ((ftd != null) && (!ftd.getIds().isEmpty())) {
201                 throw new CmisConstraintException("deleteTree could not delete all folder children: " + ftd.getIds());
202             }
203 
204             return null;
205         }
206 
207         return super.save();
208     }
209 }