-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable paging for
/submodel/submodel-elements/$path
(#920)
* fix paging for GetAllSubmodelElementsPath * update changelog
- Loading branch information
Showing
7 changed files
with
149 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...aaast/service/endpoint/http/response/mapper/GetAllSubmodelElementsPathResponseMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige | ||
* Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten | ||
* Forschung e.V. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.response.mapper; | ||
|
||
import de.fraunhofer.iosb.ilt.faaast.service.ServiceContext; | ||
import de.fraunhofer.iosb.ilt.faaast.service.dataformat.SerializationException; | ||
import de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.serialization.HttpJsonApiSerializer; | ||
import de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.util.HttpHelper; | ||
import de.fraunhofer.iosb.ilt.faaast.service.model.api.MessageType; | ||
import de.fraunhofer.iosb.ilt.faaast.service.model.api.Result; | ||
import de.fraunhofer.iosb.ilt.faaast.service.model.api.StatusCode; | ||
import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.Page; | ||
import de.fraunhofer.iosb.ilt.faaast.service.model.api.request.submodel.GetAllSubmodelElementsPathRequest; | ||
import de.fraunhofer.iosb.ilt.faaast.service.model.api.response.submodel.GetAllSubmodelElementsPathResponse; | ||
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.InvalidRequestException; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
||
/** | ||
* HTTP response mapper for {@link GetAllSubmodelElementsPathResponse}. | ||
*/ | ||
public class GetAllSubmodelElementsPathResponseMapper extends AbstractResponseMapper<GetAllSubmodelElementsPathResponse, GetAllSubmodelElementsPathRequest> { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(GetAllSubmodelElementsPathResponseMapper.class); | ||
|
||
public GetAllSubmodelElementsPathResponseMapper(ServiceContext serviceContext) { | ||
super(serviceContext); | ||
} | ||
|
||
|
||
@Override | ||
public void map(GetAllSubmodelElementsPathRequest apiRequest, GetAllSubmodelElementsPathResponse apiResponse, HttpServletResponse httpResponse) throws InvalidRequestException { | ||
Page<String> result = Page.of( | ||
apiResponse.getPayload().getContent().stream().map(Object::toString).toList(), | ||
apiResponse.getPayload().getMetadata()); | ||
try { | ||
HttpHelper.sendJson(httpResponse, | ||
apiResponse.getStatusCode(), | ||
new HttpJsonApiSerializer().write(result)); | ||
} | ||
catch (SerializationException e) { | ||
LOGGER.warn("error serializing response", e); | ||
HttpHelper.send( | ||
httpResponse, | ||
StatusCode.SERVER_INTERNAL_ERROR, | ||
Result.builder() | ||
.message(MessageType.EXCEPTION, e.getMessage()) | ||
.build()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters