Package: CompositeDIDLAdapterSupport
CompositeDIDLAdapterSupport
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
CompositeDIDLAdapterSupport(As, ResourceServer) |
|
|
|
|
|
||||||||||||||||||||
lambda$toContent$0(DIDLContent, Entity) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
||||||||||||||||||||
toContent(BrowseFlag, int, int) |
|
|
|
|
|
Coverage
1: /*
2: * *********************************************************************************************************************
3: *
4: * blueMarine II: Semantic Media Centre
5: * http://tidalwave.it/projects/bluemarine2
6: *
7: * Copyright (C) 2015 - 2021 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/bluemarine2-src
23: * git clone https://github.com/tidalwave-it/bluemarine2-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.bluemarine2.upnp.mediaserver.impl.didl;
28:
29: import javax.annotation.Nonnegative;
30: import javax.annotation.Nonnull;
31: import javax.annotation.concurrent.Immutable;
32: import org.fourthline.cling.support.model.BrowseFlag;
33: import org.fourthline.cling.support.model.DIDLContent;
34: import it.tidalwave.util.As;
35: import it.tidalwave.util.Finder;
36: import it.tidalwave.bluemarine2.model.spi.Entity;
37: import it.tidalwave.bluemarine2.rest.spi.ResourceServer;
38: import lombok.extern.slf4j.Slf4j;
39: import static it.tidalwave.util.FunctionalCheckedExceptionWrappers.*;
40: import static it.tidalwave.role.SimpleComposite._SimpleComposite_;
41:
42: /***********************************************************************************************************************
43: *
44: * @stereotype Role
45: *
46: * @author Fabrizio Giudici
47: *
48: **********************************************************************************************************************/
49: @Immutable @Slf4j
50: public abstract class CompositeDIDLAdapterSupport<T extends As> extends DIDLAdapterSupport<T>
51: {
52: public CompositeDIDLAdapterSupport (@Nonnull final T datum, @Nonnull final ResourceServer server)
53: {
54: super(datum, server);
55: }
56:
57: /*******************************************************************************************************************
58: *
59: * {@inheritDoc}
60: *
61: ******************************************************************************************************************/
62: @Override @Nonnull
63: public ContentHolder toContent (@Nonnull final BrowseFlag browseFlag,
64: @Nonnegative final int from,
65: @Nonnegative final int maxResults)
66: throws Exception
67: {
68: final DIDLContent content = new DIDLContent();
69: int numberReturned = 0;
70: int totalMatches = 0;
71:
72:• switch (browseFlag)
73: {
74: case METADATA:
75: totalMatches = numberReturned = 1;
76: content.addObject(toObject());
77: break;
78:
79: case DIRECT_CHILDREN:
80: final Finder<Entity> finder = datum.as(_SimpleComposite_).findChildren();
81: totalMatches = finder.count();
82: finder.from(from)
83: .max(maxResults)
84: .results()
85: .forEach(_c(child -> content.addObject(child.as(_DIDLAdapter_).toObject())));
86: numberReturned = (int)content.getCount();
87: break;
88:
89: default:
90: throw new IllegalArgumentException(browseFlag.toString());
91: }
92:
93: return new ContentHolder(content, numberReturned, totalMatches);
94: }
95: }