001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.isis.viewer.restfulobjects.rendering.eventserializer; 020 021import java.util.Collections; 022import java.util.List; 023import java.util.Set; 024 025import com.google.common.collect.Lists; 026import com.google.common.collect.Sets; 027 028import org.apache.isis.applib.annotation.Where; 029import org.apache.isis.applib.profiles.Localization; 030import org.apache.isis.core.commons.authentication.AuthenticationSession; 031import org.apache.isis.core.commons.config.IsisConfiguration; 032import org.apache.isis.core.metamodel.adapter.ObjectAdapter; 033import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager; 034import org.apache.isis.core.metamodel.adapter.oid.Oid; 035import org.apache.isis.core.runtime.system.context.IsisContext; 036import org.apache.isis.core.runtime.system.persistence.PersistenceSession; 037import org.apache.isis.viewer.restfulobjects.rendering.RendererContext; 038 039public class EventSerializerRendererContext implements RendererContext { 040 041 private final String baseUrl; 042 private final Where where; 043 044 public EventSerializerRendererContext(String baseUrl, Where where) { 045 this.baseUrl = baseUrl; 046 this.where = where; 047 } 048 049 @Override 050 public String urlFor(String url) { 051 return baseUrl + url; 052 } 053 054 @Override 055 public AuthenticationSession getAuthenticationSession() { 056 return IsisContext.getAuthenticationSession(); 057 } 058 059 @Override 060 public PersistenceSession getPersistenceSession() { 061 return IsisContext.getPersistenceSession(); 062 } 063 064 @Override 065 public IsisConfiguration getConfiguration() { 066 return IsisContext.getConfiguration(); 067 } 068 069 @Override 070 public AdapterManager getAdapterManager() { 071 return getPersistenceSession().getAdapterManager(); 072 } 073 074 @Override 075 public List<List<String>> getFollowLinks() { 076 return Collections.emptyList(); 077 } 078 079 @Override 080 public Where getWhere() { 081 return where; 082 } 083 084 @Override 085 public Localization getLocalization() { 086 return IsisContext.getLocalization(); 087 } 088 089 private Set<Oid> rendered = Sets.newHashSet(); 090 @Override 091 public boolean canEagerlyRender(ObjectAdapter objectAdapter) { 092 final Oid oid = objectAdapter.getOid(); 093 return rendered.add(oid); 094 } 095 096 097 098}