Skip to content

Commit 0368bca

Browse files
committed
spotless
1 parent 6fac279 commit 0368bca

File tree

3 files changed

+108
-109
lines changed

3 files changed

+108
-109
lines changed

cds-feature-attachments/src/main/java/com/sap/cds/feature/attachments/handler/applicationservice/ReadAttachmentsHandler.java

Lines changed: 105 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -54,118 +54,118 @@
5454
@ServiceName(value = "*", type = ApplicationService.class)
5555
public class ReadAttachmentsHandler implements EventHandler {
5656

57-
private static final Logger logger = LoggerFactory.getLogger(ReadAttachmentsHandler.class);
58-
59-
private final AttachmentService attachmentService;
60-
private final AttachmentStatusValidator statusValidator;
61-
private final AsyncMalwareScanExecutor scanExecutor;
62-
63-
public ReadAttachmentsHandler(
64-
AttachmentService attachmentService,
65-
AttachmentStatusValidator statusValidator,
66-
AsyncMalwareScanExecutor scanExecutor) {
67-
this.attachmentService =
68-
requireNonNull(attachmentService, "attachmentService must not be null");
69-
this.statusValidator = requireNonNull(statusValidator, "statusValidator must not be null");
70-
this.scanExecutor = requireNonNull(scanExecutor, "scanExecutor must not be null");
57+
private static final Logger logger = LoggerFactory.getLogger(ReadAttachmentsHandler.class);
58+
59+
private final AttachmentService attachmentService;
60+
private final AttachmentStatusValidator statusValidator;
61+
private final AsyncMalwareScanExecutor scanExecutor;
62+
63+
public ReadAttachmentsHandler(
64+
AttachmentService attachmentService,
65+
AttachmentStatusValidator statusValidator,
66+
AsyncMalwareScanExecutor scanExecutor) {
67+
this.attachmentService =
68+
requireNonNull(attachmentService, "attachmentService must not be null");
69+
this.statusValidator = requireNonNull(statusValidator, "statusValidator must not be null");
70+
this.scanExecutor = requireNonNull(scanExecutor, "scanExecutor must not be null");
71+
}
72+
73+
@Before
74+
@HandlerOrder(HandlerOrder.EARLY)
75+
void processBefore(CdsReadEventContext context) {
76+
logger.debug("Processing before {} for entity {}.", context.getEvent(), context.getTarget());
77+
78+
CdsModel cdsModel = context.getModel();
79+
List<String> fieldNames =
80+
getAttachmentAssociations(cdsModel, context.getTarget(), "", new ArrayList<>());
81+
if (!fieldNames.isEmpty()) {
82+
CqnSelect resultCqn = CQL.copy(context.getCqn(), new BeforeReadItemsModifier(fieldNames));
83+
context.setCqn(resultCqn);
7184
}
72-
73-
@Before
74-
@HandlerOrder(HandlerOrder.EARLY)
75-
void processBefore(CdsReadEventContext context) {
76-
logger.debug("Processing before {} for entity {}.", context.getEvent(), context.getTarget());
77-
78-
CdsModel cdsModel = context.getModel();
79-
List<String> fieldNames =
80-
getAttachmentAssociations(cdsModel, context.getTarget(), "", new ArrayList<>());
81-
if (!fieldNames.isEmpty()) {
82-
CqnSelect resultCqn = CQL.copy(context.getCqn(), new BeforeReadItemsModifier(fieldNames));
83-
context.setCqn(resultCqn);
84-
}
85+
}
86+
87+
@After
88+
@HandlerOrder(HandlerOrder.EARLY)
89+
void processAfter(CdsReadEventContext context, List<CdsData> data) {
90+
if (ApplicationHandlerHelper.containsContentField(context.getTarget(), data)) {
91+
logger.debug(
92+
"Processing after {} event for entity {}", context.getEvent(), context.getTarget());
93+
94+
Converter converter =
95+
(path, element, value) -> {
96+
Attachments attachment = Attachments.of(path.target().values());
97+
InputStream content = attachment.getContent();
98+
if (nonNull(attachment.getContentId())) {
99+
verifyStatus(path, attachment);
100+
Supplier<InputStream> supplier =
101+
nonNull(content)
102+
? () -> content
103+
: () -> attachmentService.readAttachment(attachment.getContentId());
104+
return new LazyProxyInputStream(supplier, statusValidator, attachment.getStatus());
105+
} else {
106+
return value;
107+
}
108+
};
109+
CdsDataProcessor.create()
110+
.addConverter(ApplicationHandlerHelper.MEDIA_CONTENT_FILTER, converter)
111+
.process(data, context.getTarget());
85112
}
113+
}
86114

87-
@After
88-
@HandlerOrder(HandlerOrder.EARLY)
89-
void processAfter(CdsReadEventContext context, List<CdsData> data) {
90-
if (ApplicationHandlerHelper.containsContentField(context.getTarget(), data)) {
91-
logger.debug(
92-
"Processing after {} event for entity {}", context.getEvent(), context.getTarget());
93-
94-
Converter converter =
95-
(path, element, value) -> {
96-
Attachments attachment = Attachments.of(path.target().values());
97-
InputStream content = attachment.getContent();
98-
if (nonNull(attachment.getContentId())) {
99-
verifyStatus(path, attachment);
100-
Supplier<InputStream> supplier =
101-
nonNull(content)
102-
? () -> content
103-
: () -> attachmentService.readAttachment(attachment.getContentId());
104-
return new LazyProxyInputStream(supplier, statusValidator, attachment.getStatus());
105-
} else {
106-
return value;
107-
}
108-
};
109-
CdsDataProcessor.create()
110-
.addConverter(ApplicationHandlerHelper.MEDIA_CONTENT_FILTER, converter)
111-
.process(data, context.getTarget());
112-
}
115+
private List<String> getAttachmentAssociations(
116+
CdsModel model, CdsEntity entity, String associationName, List<String> processedEntities) {
117+
List<String> associationNames = new ArrayList<>();
118+
if (ApplicationHandlerHelper.isMediaEntity(entity)) {
119+
associationNames.add(associationName);
113120
}
114121

115-
private List<String> getAttachmentAssociations(
116-
CdsModel model, CdsEntity entity, String associationName, List<String> processedEntities) {
117-
List<String> associationNames = new ArrayList<>();
118-
if (ApplicationHandlerHelper.isMediaEntity(entity)) {
119-
associationNames.add(associationName);
120-
}
121-
122-
Map<String, CdsEntity> annotatedEntities =
123-
entity
124-
.associations()
125-
.collect(
126-
Collectors.toMap(
127-
CdsElementDefinition::getName,
128-
element -> element.getType().as(CdsAssociationType.class).getTarget()));
129-
130-
if (annotatedEntities.isEmpty()) {
131-
return associationNames;
132-
}
133-
134-
for (Entry<String, CdsEntity> associatedElement : annotatedEntities.entrySet()) {
135-
if (!associationNames.contains(associatedElement.getKey())
136-
&& !processedEntities.contains(associatedElement.getKey())
137-
&& !Drafts.SIBLING_ENTITY.equals(associatedElement.getKey())) {
138-
processedEntities.add(associatedElement.getKey());
139-
List<String> result =
140-
getAttachmentAssociations(
141-
model, associatedElement.getValue(), associatedElement.getKey(), processedEntities);
142-
associationNames.addAll(result);
143-
}
144-
}
145-
return associationNames;
146-
}
122+
Map<String, CdsEntity> annotatedEntities =
123+
entity
124+
.associations()
125+
.collect(
126+
Collectors.toMap(
127+
CdsElementDefinition::getName,
128+
element -> element.getType().as(CdsAssociationType.class).getTarget()));
147129

148-
private void verifyStatus(Path path, Attachments attachment) {
149-
if (areKeysEmpty(path.target().keys())) {
150-
String currentStatus = attachment.getStatus();
151-
logger.debug(
152-
"In verify status for content id {} and status {}",
153-
attachment.getContentId(),
154-
currentStatus);
155-
if (StatusCode.UNSCANNED.equals(currentStatus)
156-
|| StatusCode.SCANNING.equals(currentStatus)
157-
|| currentStatus == null) {
158-
logger.debug(
159-
"Scanning content with ID {} for malware, has current status {}",
160-
attachment.getContentId(),
161-
currentStatus);
162-
scanExecutor.scanAsync(path.target().entity(), attachment.getContentId());
163-
}
164-
statusValidator.verifyStatus(attachment.getStatus());
165-
}
130+
if (annotatedEntities.isEmpty()) {
131+
return associationNames;
166132
}
167133

168-
private boolean areKeysEmpty(Map<String, Object> keys) {
169-
return keys.values().stream().allMatch(Objects::isNull);
134+
for (Entry<String, CdsEntity> associatedElement : annotatedEntities.entrySet()) {
135+
if (!associationNames.contains(associatedElement.getKey())
136+
&& !processedEntities.contains(associatedElement.getKey())
137+
&& !Drafts.SIBLING_ENTITY.equals(associatedElement.getKey())) {
138+
processedEntities.add(associatedElement.getKey());
139+
List<String> result =
140+
getAttachmentAssociations(
141+
model, associatedElement.getValue(), associatedElement.getKey(), processedEntities);
142+
associationNames.addAll(result);
143+
}
144+
}
145+
return associationNames;
146+
}
147+
148+
private void verifyStatus(Path path, Attachments attachment) {
149+
if (areKeysEmpty(path.target().keys())) {
150+
String currentStatus = attachment.getStatus();
151+
logger.debug(
152+
"In verify status for content id {} and status {}",
153+
attachment.getContentId(),
154+
currentStatus);
155+
if (StatusCode.UNSCANNED.equals(currentStatus)
156+
|| StatusCode.SCANNING.equals(currentStatus)
157+
|| currentStatus == null) {
158+
logger.debug(
159+
"Scanning content with ID {} for malware, has current status {}",
160+
attachment.getContentId(),
161+
currentStatus);
162+
scanExecutor.scanAsync(path.target().entity(), attachment.getContentId());
163+
}
164+
statusValidator.verifyStatus(attachment.getStatus());
170165
}
166+
}
167+
168+
private boolean areKeysEmpty(Map<String, Object> keys) {
169+
return keys.values().stream().allMatch(Objects::isNull);
170+
}
171171
}

cds-feature-attachments/src/main/java/com/sap/cds/feature/attachments/handler/applicationservice/readhelper/AttachmentStatusValidator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
package com.sap.cds.feature.attachments.handler.applicationservice.readhelper;
55

6-
//import com.sap.cds.feature.attachments.generated.cds4j.sap.attachments.StatusCode;
6+
// import com.sap.cds.feature.attachments.generated.cds4j.sap.attachments.StatusCode;
77

88
/**
99
* The class {@link AttachmentStatusValidator} is responsible for validating the status of an
@@ -19,11 +19,11 @@ public class AttachmentStatusValidator {
1919
*/
2020
public void verifyStatus(String attachmentStatus) throws AttachmentStatusException {
2121
throw AttachmentStatusException.getNotCleanException();
22-
//if (!StatusCode.CLEAN.equals(attachmentStatus)) {
22+
// if (!StatusCode.CLEAN.equals(attachmentStatus)) {
2323
// throw StatusCode.UNSCANNED.equals(attachmentStatus)
2424
// || StatusCode.SCANNING.equals(attachmentStatus)
2525
// ? AttachmentStatusException.getNotScannedException()
2626
// : AttachmentStatusException.getNotCleanException();
27-
//}
27+
// }
2828
}
2929
}

pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@
289289
</executions>
290290
</plugin>
291291

292-
293292
<plugin>
294293
<artifactId>maven-enforcer-plugin</artifactId>
295294
<executions>

0 commit comments

Comments
 (0)