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.ui;
021
022import java.util.Collections;
023import java.util.List;
024import javax.inject.Inject;
025import javax.inject.Named;
026import org.springframework.core.annotation.Order;
027import org.apache.isis.applib.annotation.Action;
028import org.apache.isis.applib.annotation.ActionLayout;
029import org.apache.isis.applib.annotation.DomainService;
030import org.apache.isis.applib.annotation.DomainServiceLayout;
031import org.apache.isis.applib.annotation.MemberOrder;
032import org.apache.isis.applib.annotation.NatureOfService;
033import org.apache.isis.applib.annotation.OrderPrecedence;
034import org.apache.isis.applib.annotation.SemanticsOf;
035import org.apache.isis.applib.services.jaxb.JaxbService;
036import org.apache.isis.applib.value.Clob;
037import org.apache.isis.extensions.commandlog.impl.jdo.CommandJdo;
038import org.apache.isis.extensions.commandlog.impl.jdo.CommandJdoRepository;
039import org.apache.isis.extensions.commandreplay.secondary.IsisModuleExtCommandReplaySecondary;
040import org.apache.isis.schema.cmd.v2.CommandDto;
041import org.apache.isis.schema.cmd.v2.CommandsDto;
042
043@DomainService(nature = NatureOfService.VIEW, objectType = "isisExtensionsCommandReplaySecondary.CommandReplayOnSecondaryService")
044@DomainServiceLayout(named = "Activity", menuBar = DomainServiceLayout.MenuBar.SECONDARY)
045@Named("isisExtensionsCommandReplaySecondary.CommandReplayOnSecondaryService")
046@Order(OrderPrecedence.MIDPOINT)
047public class CommandReplayOnSecondaryService {
048    @java.lang.SuppressWarnings("all")
049    private static final org.apache.logging.log4j.Logger log = org.apache.logging.log4j.LogManager.getLogger(CommandReplayOnSecondaryService.class);
050    @Inject
051    final CommandJdoRepository commandJdoRepository;
052    @Inject
053    final JaxbService jaxbService;
054
055
056    public static abstract class ActionDomainEvent extends IsisModuleExtCommandReplaySecondary.ActionDomainEvent<CommandReplayOnSecondaryService> {
057    }
058
059
060    public static class FindMostRecentReplayedDomainEvent extends ActionDomainEvent {
061    }
062
063    @Action(domainEvent = FindMostRecentReplayedDomainEvent.class, semantics = SemanticsOf.SAFE)
064    @ActionLayout(cssClassFa = "fa-bath")
065    @MemberOrder(sequence = "60.1")
066    public CommandJdo findMostRecentReplayed() {
067        return commandJdoRepository.findMostRecentReplayed().orElse(null);
068    }
069
070
071    public static class UploadCommandsDomainEvent extends ActionDomainEvent {
072    }
073
074    @Action(domainEvent = UploadCommandsDomainEvent.class, semantics = SemanticsOf.NON_IDEMPOTENT)
075    @ActionLayout(cssClassFa = "fa-upload")
076    @MemberOrder(sequence = "60.2")
077    public void uploadCommands(final Clob commandsDtoAsXml) {
078        final java.lang.CharSequence chars = commandsDtoAsXml.getChars();
079        List<CommandDto> commandDtoList;
080        try {
081            final org.apache.isis.schema.cmd.v2.CommandsDto commandsDto = jaxbService.fromXml(CommandsDto.class, chars.toString());
082            commandDtoList = commandsDto.getCommandDto();
083        } catch (Exception ex) {
084            final org.apache.isis.schema.cmd.v2.CommandDto commandDto = jaxbService.fromXml(CommandDto.class, chars.toString());
085            commandDtoList = Collections.singletonList(commandDto);
086        }
087        for (final CommandDto commandDto : commandDtoList) {
088            commandJdoRepository.saveForReplay(commandDto);
089        }
090    }
091
092    @java.lang.SuppressWarnings("all")
093    public CommandReplayOnSecondaryService(final CommandJdoRepository commandJdoRepository, final JaxbService jaxbService) {
094        this.commandJdoRepository = commandJdoRepository;
095        this.jaxbService = jaxbService;
096    }
097}