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.analyser; 021 022import javax.annotation.PostConstruct; 023import javax.inject.Named; 024import com.google.common.base.Objects; 025import org.springframework.core.annotation.Order; 026import org.springframework.stereotype.Service; 027import org.apache.isis.applib.annotation.OrderPrecedence; 028import org.apache.isis.applib.services.commanddto.conmap.UserDataKeys; 029import org.apache.isis.applib.util.schema.CommandDtoUtils; 030import org.apache.isis.core.config.IsisConfiguration; 031import org.apache.isis.extensions.commandlog.impl.jdo.CommandJdo; 032import org.apache.isis.schema.cmd.v2.CommandDto; 033import org.apache.isis.schema.common.v2.InteractionType; 034 035@Service 036@Named("isisExtensionsCommandReplaySecondary.CommandReplayAnalyserResult") 037@Order(OrderPrecedence.MIDPOINT) 038public class CommandReplayAnalyserResult implements CommandReplayAnalyser { 039 private final IsisConfiguration isisConfiguration; 040 private boolean enabled; 041 042 @PostConstruct 043 public void init() { 044 enabled = isisConfiguration.getExtensions().getCommandReplay().getAnalyser().getException().isEnabled(); 045 } 046 047 @Override 048 public String analyzeReplay(final CommandJdo commandJdo) { 049 if (!enabled) { 050 return null; 051 } 052 final org.apache.isis.schema.cmd.v2.CommandDto dto = commandJdo.getCommandDto(); 053 if (dto.getMember().getInteractionType() == InteractionType.PROPERTY_EDIT) { 054 return null; 055 } 056 // see if the outcome was the same... 057 // ... either the same result when replayed 058 final java.lang.String primaryResultStr = CommandDtoUtils.getUserData(dto, UserDataKeys.RESULT); 059 final org.apache.isis.applib.services.bookmark.Bookmark secondaryResult = commandJdo.getResult(); 060 final java.lang.String secondaryResultStr = secondaryResult != null ? secondaryResult.toString() : null; 061 return Objects.equal(primaryResultStr, secondaryResultStr) ? null : String.format("Results differ. Primary was \'%s\', secondary is \'%s\'", primaryResultStr, secondaryResultStr); 062 } 063 064 @java.lang.SuppressWarnings("all") 065 public CommandReplayAnalyserResult(final IsisConfiguration isisConfiguration) { 066 this.isisConfiguration = isisConfiguration; 067 } 068}