001// Generated by delombok at Mon Oct 12 22:59:35 BST 2020
002/*
003 *  Licensed to the Apache Software Foundation (ASF) under one
004 *  or more contributor license agreements.  See the NOTICE file
005 *  distributed with this work for additional information
006 *  regarding copyright ownership.  The ASF licenses this file
007 *  to you under the Apache License, Version 2.0 (the
008 *  "License"); you may not use this file except in compliance
009 *  with the License.  You may obtain a copy of the License at
010 *
011 *        http://www.apache.org/licenses/LICENSE-2.0
012 *
013 *  Unless required by applicable law or agreed to in writing,
014 *  software distributed under the License is distributed on an
015 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 *  KIND, either express or implied.  See the License for the
017 *  specific language governing permissions and limitations
018 *  under the License.
019 */
020package org.apache.isis.extensions.commandreplay.secondary.mixins;
021
022import java.net.MalformedURLException;
023import java.net.URL;
024import javax.inject.Inject;
025import org.apache.isis.applib.ApplicationException;
026import org.apache.isis.applib.annotation.Action;
027import org.apache.isis.applib.annotation.MemberOrder;
028import org.apache.isis.applib.annotation.RestrictTo;
029import org.apache.isis.applib.annotation.SemanticsOf;
030import org.apache.isis.applib.services.bookmark.BookmarkService;
031import org.apache.isis.extensions.commandlog.impl.jdo.CommandJdo;
032import org.apache.isis.extensions.commandreplay.secondary.IsisModuleExtCommandReplaySecondary;
033import org.apache.isis.extensions.commandreplay.secondary.config.SecondaryConfig;
034
035@Action(semantics = SemanticsOf.SAFE, domainEvent = Object_openOnPrimary.ActionDomainEvent.class, restrictTo = RestrictTo.PROTOTYPING)
036public class Object_openOnPrimary {
037
038    public static class ActionDomainEvent extends IsisModuleExtCommandReplaySecondary.ActionDomainEvent<Object_openOnPrimary> {
039    }
040
041    final Object object;
042
043    public URL act() {
044        final java.lang.String baseUrlPrefix = lookupBaseUrlPrefix();
045        final java.lang.String urlSuffix = bookmarkService.bookmarkFor(object).toString();
046        try {
047            return new URL(baseUrlPrefix + urlSuffix);
048        } catch (MalformedURLException e) {
049            throw new ApplicationException(e);
050        }
051    }
052
053    public boolean hideAct() {
054        return !secondaryConfig.isConfigured();
055    }
056
057    private String lookupBaseUrlPrefix() {
058        return secondaryConfig.getPrimaryBaseUrlWicket() + "entity/";
059    }
060
061    @Inject
062    SecondaryConfig secondaryConfig;
063    @Inject
064    BookmarkService bookmarkService;
065
066    @java.lang.SuppressWarnings("all")
067    public Object_openOnPrimary(final Object object) {
068        this.object = object;
069    }
070}