| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
package org.apache.chemistry.opencmis.server.impl.atompub; |
| 20 | |
|
| 21 | |
import org.apache.chemistry.opencmis.commons.data.ObjectData; |
| 22 | |
import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException; |
| 23 | |
import org.apache.chemistry.opencmis.commons.impl.Constants; |
| 24 | |
import org.apache.chemistry.opencmis.commons.impl.UrlBuilder; |
| 25 | |
import org.apache.chemistry.opencmis.commons.server.CallContext; |
| 26 | |
import org.apache.chemistry.opencmis.commons.server.CmisService; |
| 27 | |
import org.apache.chemistry.opencmis.commons.server.ObjectInfo; |
| 28 | |
import org.apache.chemistry.opencmis.commons.spi.Holder; |
| 29 | |
import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_ENTRY; |
| 30 | |
import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.compileBaseUrl; |
| 31 | |
import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.compileUrl; |
| 32 | |
import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.writeObjectEntry; |
| 33 | |
import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getBooleanParameter; |
| 34 | |
import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getStringParameter; |
| 35 | |
|
| 36 | |
import java.util.List; |
| 37 | |
|
| 38 | |
import javax.servlet.http.HttpServletRequest; |
| 39 | |
import javax.servlet.http.HttpServletResponse; |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
public class VersioningService |
| 46 | |
{ |
| 47 | |
private VersioningService( ) |
| 48 | 0 | { |
| 49 | 0 | } |
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
public static void checkOut( CallContext context, CmisService service, String repositoryId, |
| 55 | |
HttpServletRequest request, HttpServletResponse response ) |
| 56 | |
throws Exception |
| 57 | |
{ |
| 58 | |
|
| 59 | 0 | AtomEntryParser parser = new AtomEntryParser( context.getTempDirectory( ), context.getMemoryThreshold( ) ); |
| 60 | 0 | parser.setIgnoreAtomContentSrc( true ); |
| 61 | 0 | parser.parse( request.getInputStream( ) ); |
| 62 | |
|
| 63 | |
|
| 64 | 0 | Holder<String> checkOutId = new Holder<String>( parser.getId( ) ); |
| 65 | 0 | service.checkOut( repositoryId, checkOutId, null, null ); |
| 66 | |
|
| 67 | 0 | ObjectInfo objectInfo = service.getObjectInfo( repositoryId, checkOutId.getValue( ) ); |
| 68 | |
|
| 69 | 0 | if ( objectInfo == null ) |
| 70 | |
{ |
| 71 | 0 | throw new CmisRuntimeException( "Object Info is missing!" ); |
| 72 | |
} |
| 73 | |
|
| 74 | 0 | ObjectData object = objectInfo.getObject( ); |
| 75 | |
|
| 76 | 0 | if ( object == null ) |
| 77 | |
{ |
| 78 | 0 | throw new CmisRuntimeException( "Object is null!" ); |
| 79 | |
} |
| 80 | |
|
| 81 | 0 | if ( object.getId( ) == null ) |
| 82 | |
{ |
| 83 | 0 | throw new CmisRuntimeException( "Object Id is null!" ); |
| 84 | |
} |
| 85 | |
|
| 86 | |
|
| 87 | 0 | UrlBuilder baseUrl = compileBaseUrl( request, repositoryId ); |
| 88 | 0 | String location = compileUrl( baseUrl, RESOURCE_ENTRY, object.getId( ) ); |
| 89 | |
|
| 90 | 0 | response.setStatus( HttpServletResponse.SC_CREATED ); |
| 91 | 0 | response.setContentType( Constants.MEDIATYPE_ENTRY ); |
| 92 | 0 | response.setHeader( "Content-Location", location ); |
| 93 | 0 | response.setHeader( "Location", location ); |
| 94 | |
|
| 95 | |
|
| 96 | 0 | AtomEntry entry = new AtomEntry( ); |
| 97 | 0 | entry.startDocument( response.getOutputStream( ) ); |
| 98 | 0 | writeObjectEntry( service, entry, object, null, repositoryId, null, null, baseUrl, true ); |
| 99 | 0 | entry.endDocument( ); |
| 100 | 0 | } |
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
public static void getAllVersions( CallContext context, CmisService service, String repositoryId, |
| 106 | |
HttpServletRequest request, HttpServletResponse response ) |
| 107 | |
throws Exception |
| 108 | |
{ |
| 109 | |
|
| 110 | 0 | String objectId = getStringParameter( request, Constants.PARAM_ID ); |
| 111 | 0 | String versionSeriesId = getStringParameter( request, Constants.PARAM_VERSION_SERIES_ID ); |
| 112 | 0 | String filter = getStringParameter( request, Constants.PARAM_FILTER ); |
| 113 | 0 | Boolean includeAllowableActions = getBooleanParameter( request, Constants.PARAM_ALLOWABLE_ACTIONS ); |
| 114 | |
|
| 115 | |
|
| 116 | 0 | List<ObjectData> versions = service.getAllVersions( repositoryId, objectId, versionSeriesId, filter, |
| 117 | |
includeAllowableActions, null ); |
| 118 | |
|
| 119 | 0 | if ( ( versions == null ) || versions.isEmpty( ) ) |
| 120 | |
{ |
| 121 | 0 | throw new CmisRuntimeException( "Version list is null or empty!" ); |
| 122 | |
} |
| 123 | |
|
| 124 | |
|
| 125 | 0 | response.setStatus( HttpServletResponse.SC_OK ); |
| 126 | 0 | response.setContentType( Constants.MEDIATYPE_FEED ); |
| 127 | |
|
| 128 | |
|
| 129 | 0 | AtomFeed feed = new AtomFeed( ); |
| 130 | 0 | feed.startDocument( response.getOutputStream( ) ); |
| 131 | 0 | feed.startFeed( true ); |
| 132 | |
|
| 133 | |
|
| 134 | 0 | ObjectInfo latestObjectInfo = service.getObjectInfo( repositoryId, versions.get( 0 ).getId( ) ); |
| 135 | 0 | ObjectInfo firstObjectInfo = service.getObjectInfo( repositoryId, |
| 136 | 0 | versions.get( versions.size( ) - 1 ).getId( ) ); |
| 137 | |
|
| 138 | 0 | feed.writeFeedElements( versionSeriesId, firstObjectInfo.getCreatedBy( ), latestObjectInfo.getName( ), |
| 139 | 0 | latestObjectInfo.getLastModificationDate( ), null, null ); |
| 140 | |
|
| 141 | |
|
| 142 | 0 | UrlBuilder baseUrl = compileBaseUrl( request, repositoryId ); |
| 143 | |
|
| 144 | 0 | feed.writeServiceLink( baseUrl.toString( ), repositoryId ); |
| 145 | |
|
| 146 | 0 | if ( objectId != null ) |
| 147 | |
{ |
| 148 | 0 | feed.writeViaLink( compileUrl( baseUrl, RESOURCE_ENTRY, objectId ) ); |
| 149 | |
} |
| 150 | |
|
| 151 | |
|
| 152 | 0 | AtomEntry entry = new AtomEntry( feed.getWriter( ) ); |
| 153 | |
|
| 154 | 0 | for ( ObjectData object : versions ) |
| 155 | |
{ |
| 156 | 0 | if ( object == null ) |
| 157 | |
{ |
| 158 | 0 | continue; |
| 159 | |
} |
| 160 | |
|
| 161 | 0 | writeObjectEntry( service, entry, object, null, repositoryId, null, null, baseUrl, false ); |
| 162 | 0 | } |
| 163 | |
|
| 164 | |
|
| 165 | 0 | feed.endFeed( ); |
| 166 | 0 | feed.endDocument( ); |
| 167 | 0 | } |
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
public static void deleteAllVersions( CallContext context, CmisService service, String repositoryId, |
| 173 | |
HttpServletRequest request, HttpServletResponse response ) |
| 174 | |
{ |
| 175 | |
|
| 176 | 0 | String objectId = getStringParameter( request, Constants.PARAM_ID ); |
| 177 | |
|
| 178 | |
|
| 179 | 0 | service.deleteObjectOrCancelCheckOut( repositoryId, objectId, Boolean.TRUE, null ); |
| 180 | |
|
| 181 | |
|
| 182 | 0 | response.setStatus( HttpServletResponse.SC_NO_CONTENT ); |
| 183 | 0 | } |
| 184 | |
} |