Skip to content

Commit

Permalink
CAUSEWAY-3859: Java record refactoring (part 45)
Browse files Browse the repository at this point in the history
  • Loading branch information
andi-huber committed Feb 25, 2025
1 parent 7fc0773 commit d27bc33
Show file tree
Hide file tree
Showing 9 changed files with 348 additions and 410 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,15 @@
import lombok.experimental.UtilityClass;

@UtilityClass
final class _DownloadHandler {
final class DownloadHandlerFactory {

public IRequestHandler downloadHandler(
final ObjectAction action,
final Object value) {
if(value instanceof Clob) {
var clob = (Clob)value;
if(value instanceof Clob clob) {
return handlerFor(action, resourceStreamFor(clob), clob);
}
if(value instanceof Blob) {
var blob = (Blob)value;
if(value instanceof Blob blob) {
return handlerFor(action, resourceStreamFor(blob), blob);
}
return null;
Expand All @@ -59,36 +57,29 @@ public IRequestHandler downloadHandler(

private IResourceStream resourceStreamFor(final Blob blob) {
final IResourceStream resourceStream = new AbstractResourceStream() {

private static final long serialVersionUID = 1L;

@Override
public InputStream getInputStream() throws ResourceStreamNotFoundException {
return new ByteArrayInputStream(blob.getBytes());
@Override public InputStream getInputStream() throws ResourceStreamNotFoundException {
return new ByteArrayInputStream(blob.bytes());
}

@Override
public String getContentType() {
return blob.getMimeType().toString();
@Override public String getContentType() {
return blob.mimeType().toString();
}

@Override
public void close() throws IOException {
@Override public void close() throws IOException {
}
};
return resourceStream;
}

private IResourceStream resourceStreamFor(final Clob clob) {
return new StringResourceStream(clob.getChars(), clob.getMimeType().toString());
return new StringResourceStream(clob.chars(), clob.mimeType().toString());
}

private IRequestHandler handlerFor(
final ObjectAction action,
final IResourceStream resourceStream,
final NamedWithMimeType namedWithMimeType) {
var handler =
new ResourceStreamRequestHandler(resourceStream, namedWithMimeType.getName());
new ResourceStreamRequestHandler(resourceStream, namedWithMimeType.name());
handler.setContentDisposition(ContentDisposition.ATTACHMENT);

//CAUSEWAY-1619, prevent clients from caching the response content
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.causeway.viewer.wicket.ui.actionresponse;

import org.apache.wicket.ajax.AjaxRequestTarget;

import org.apache.causeway.commons.functional.Either;
import org.apache.causeway.core.metamodel.object.ManagedObject;
import org.apache.causeway.viewer.wicket.model.models.ActionModel;
import org.apache.causeway.viewer.wicket.model.models.PropertyModel;

public record ExecutionResultHandler(Either<ActionModel, PropertyModel> actionOrPropertyModel) {

public void handle(final AjaxRequestTarget ajaxTarget, final ManagedObject result) {
// triggers ManagedObject.getBookmarkRefreshed()
var mediator = actionOrPropertyModel.fold(
act->Mediator.determineAndInterpretResult(act, ajaxTarget, result),
prop->Mediator.toDomainObjectPage(result));

// redirect using associated strategy
// on property edit, triggers SQL update (on JPA)
mediator.handle();
}

}
Loading

0 comments on commit d27bc33

Please sign in to comment.