11package org .roda .wui .api .v2 .services ;
22
3- import java .io .PrintStream ;
43import java .util .ArrayList ;
54import java .util .Collections ;
65import java .util .HashMap ;
1110import java .util .Optional ;
1211
1312import org .apache .commons .lang3 .StringUtils ;
14- import org .apache .coyote .Request ;
1513import org .roda .core .RodaCoreFactory ;
1614import org .roda .core .common .Messages ;
1715import org .roda .core .common .iterables .CloseableIterables ;
2220import org .roda .core .data .exceptions .NotFoundException ;
2321import org .roda .core .data .exceptions .RODAException ;
2422import org .roda .core .data .exceptions .RequestNotValidException ;
25- import org .roda .core .data .v2 .ConsumesOutputStream ;
26- import org .roda .core .data .v2 .DefaultConsumesOutputStream ;
2723import org .roda .core .data .v2 .StreamResponse ;
2824import org .roda .core .data .v2 .index .select .SelectedItems ;
2925import org .roda .core .data .v2 .ip .IndexedRepresentation ;
4541import org .roda .core .plugins .base .maintenance .ChangeRepresentationStatusPlugin ;
4642import org .roda .core .plugins .base .maintenance .ChangeTypePlugin ;
4743import org .roda .core .plugins .base .maintenance .DeleteRODAObjectPlugin ;
48- import org .roda .core .storage .Binary ;
4944import org .roda .wui .api .v2 .utils .ApiUtils ;
5045import org .roda .wui .api .v2 .utils .CommonServicesUtils ;
51- import org .roda .wui .common .HTMLUtils ;
5246import org .roda .wui .common .model .RequestContext ;
5347import org .roda .wui .common .server .ServerTools ;
5448import org .slf4j .Logger ;
6155@ Service
6256public class RepresentationService {
6357 private static final Logger LOGGER = LoggerFactory .getLogger (RepresentationService .class );
64- private static final String HTML_EXT = ".html" ;
6558
66- private static DescriptiveMetadataInfo retrieveDescriptiveMetadataBundle (String aipId , String representationId ,
59+ private static DescriptiveMetadataInfo retrieveDescriptiveMetadataBundle (ModelService model ,
6760 DescriptiveMetadata descriptiveMetadata , final Locale locale ) {
68- ModelService model = RodaCoreFactory .getModelService ();
6961 Messages messages = RodaCoreFactory .getI18NMessages (locale );
7062 DescriptiveMetadataInfo info = new DescriptiveMetadataInfo ();
7163 info .setId (descriptiveMetadata .getId ());
@@ -107,7 +99,8 @@ public Representation retrieveAIPRepresentation(RequestContext requestContext, I
10799 return model .retrieveRepresentation (aipId , representationId );
108100 }
109101
110- public StreamResponse retrieveAIPRepresentationBinary (RequestContext requestContext , IndexedRepresentation representation )
102+ public StreamResponse retrieveAIPRepresentationBinary (RequestContext requestContext ,
103+ IndexedRepresentation representation )
111104 throws GenericException , RequestNotValidException , NotFoundException , AuthorizationDeniedException {
112105 return ApiUtils .download (requestContext , representation );
113106 }
@@ -203,35 +196,15 @@ private static List<DescriptiveMetadata> orderDescriptiveMetadata(List<Descripti
203196 return orderedMetadata ;
204197 }
205198
206- public StreamResponse retrieveRepresentationDescriptiveMetadata (String aipId , String representationId ,
207- String metadataId , String localeString )
208- throws AuthorizationDeniedException , RequestNotValidException , NotFoundException , GenericException {
209- ModelService modelService = RodaCoreFactory .getModelService ();
210- Binary descriptiveMetadataBinary = modelService .retrieveDescriptiveMetadataBinary (aipId , representationId ,
211- metadataId );
212- String filename = descriptiveMetadataBinary .getStoragePath ().getName () + HTML_EXT ;
213- DescriptiveMetadata descriptiveMetadata = modelService .retrieveDescriptiveMetadata (aipId , representationId ,
214- metadataId );
215- String htmlDescriptive = HTMLUtils .descriptiveMetadataToHtml (descriptiveMetadataBinary ,
216- descriptiveMetadata .getType (), descriptiveMetadata .getVersion (), ServerTools .parseLocale (localeString ));
217-
218- ConsumesOutputStream stream = new DefaultConsumesOutputStream (filename , RodaConstants .MEDIA_TYPE_TEXT_HTML , out -> {
219- PrintStream printStream = new PrintStream (out );
220- printStream .print (htmlDescriptive );
221- printStream .close ();
222- });
223-
224- return new StreamResponse (stream );
225- }
226-
227- public StreamResponse retrieveAIPRepresentationOtherMetadata (RequestContext requestContext , IndexedRepresentation representation )
199+ public StreamResponse retrieveAIPRepresentationOtherMetadata (RequestContext requestContext ,
200+ IndexedRepresentation representation )
228201 throws GenericException , RequestNotValidException , NotFoundException , AuthorizationDeniedException {
229202 return ApiUtils .download (requestContext , representation , RodaConstants .STORAGE_DIRECTORY_METADATA ,
230203 RodaConstants .STORAGE_DIRECTORY_OTHER );
231204 }
232205
233- public DescriptiveMetadataInfos getDescriptiveMetadata (RequestContext requestContext , IndexedRepresentation indexedRepresentation ,
234- String localeString )
206+ public DescriptiveMetadataInfos getDescriptiveMetadata (RequestContext requestContext ,
207+ IndexedRepresentation indexedRepresentation , String localeString )
235208 throws AuthorizationDeniedException , RequestNotValidException , NotFoundException , GenericException {
236209 Locale locale = ServerTools .parseLocale (localeString );
237210 DescriptiveMetadataInfos descriptiveMetadataInfos = new DescriptiveMetadataInfos ();
@@ -244,8 +217,8 @@ public DescriptiveMetadataInfos getDescriptiveMetadata(RequestContext requestCon
244217 List <DescriptiveMetadata > orderedMetadata = orderDescriptiveMetadata (representation .getDescriptiveMetadata ());
245218
246219 for (DescriptiveMetadata descriptiveMetadata : orderedMetadata ) {
247- descriptiveMetadataInfos . addObject ( retrieveDescriptiveMetadataBundle ( representation . getAipId (),
248- representation . getId (), descriptiveMetadata , locale ));
220+ descriptiveMetadataInfos
221+ . addObject ( retrieveDescriptiveMetadataBundle ( requestContext . getModelService (), descriptiveMetadata , locale ));
249222 }
250223 }
251224
0 commit comments