- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在本地,我有一个 master.jrxml
报告和一些 subreport.jrxml
,可以通过 ReportDesign design = JRXmlLoader.load( "/local-file-dir/path/to/subreport.jrxml")
在 Scriptlet 代码中。
在服务器上,无论我尝试什么,上述加载方法(由我的master.jrxml
触发)显然无法处理存储库路径(基本上是net.sf.jasperreports.engine .JRException: java.io.FileNotFoundException: ...
)
(subreport.jrxml
作为 JRXML 文件资源 上传 - 不是作为带有不可见创建的文件夹结构的报告;subreport-attached.jrxml
作为我的 master.jrxml 报告的文件资源上传)
/repo/path/subreport.jrxml
repo:/repo/path/subreport.jrxml
subreport-attached.jrxml
repo:subreport-attached.jrxml
我还尝试使用在网络其他地方找到的上述 uri 变体进行以下操作但没有成功:
JRXmlLoader:
JRXmlLoader.load(
new DefaultRepositoryService(
DefaultJasperReportsContext.getInstance()
).getInputStream( subrepPath )
RepositoryUtil:
RepositoryUtil.getInstance(
DefaultJasperReportsContext.getInstance()
).getInputStreamFromLocation( subrepPath )
最佳答案
哇哦! :) 使用 com.jaspersoft.jasperserver.api.metadata.common.service.RepositoryService
的最后一种方法的工作原理如下:
JasperDesign design = JRXmlLoader.load(
( (RepositoryService) StaticApplicationContext.getApplicationContext()
.getBean( "repositoryService" )
)
.getResourceData( JasperServerUtil.getExecutionContext() ,
"repo:/some/where/subreport.jrxml" )
.getDataStream()
噗!艰难的诞生。
自从我们迁移到 JRS 7.2.0 (CE)(从 JRS 6.3.0 (CE))以来,我们意识到,上述解决方案对于临时报告执行效果很好,但在报告生成作业中运行时会抛出错误( =工作背景):
Caused by: java.lang.IllegalStateException: No thread-bound request found:
Are you referring to request attributes outside of an actual web request,
or processing a request outside of the originally receiving thread?
If you are actually operating within a web request and still receive this
message, your code is probably running outside of
DispatcherServlet/DispatcherPortlet:
In this case, use RequestContextListener or RequestContextFilter to
expose the current request.
at org.springframework.web.context.request.RequestContextHolder.
currentRequestAttributes(RequestContextHolder.java:131)
在这种情况下,我们发现了另一个更详细的单点解决方案,适用于这两种情况:
此 Jaspersoft 社区 Wiki 页面显示了一些带有 FolderHelper 的示例代码。和一个ExtendedUserFolderProcessor
您完全可以将这 2 个类添加到您的项目中
为了调用代码上的紧凑代码,我们另外将此 getExecCtx()
方法添加到 ExtendedUserFolderProcessor
:
public ExecutionContext getExecCtx() {
return new FolderHelper( getRepositoryService() , getObjectPermissionService() , getUserAuthorityService() )
.getAdminContext() ;
}
然后使用以下代码获取ExecutionContext
:
new ExtendedUserFolderProcessor().getExecCtx()
从安全角度来看,这可能不是最好的解决方案,因为使用了管理上下文/权限,但对于我们的环境来说,这很好。
为了完整起见,我将在此处复制引用的代码:(特别是因为维基百科正处于为期一周的搬迁过程中,也许有些东西可能会丢失)
package com.jaspersoft.jasperserver.api.security.externalAuth.sample.processors;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.security.core.context.SecurityContextHolder;
import com.jaspersoft.jasperserver.api.common.domain.ExecutionContext;
import com.jaspersoft.jasperserver.api.common.domain.impl.ExecutionContextImpl;
import com.jaspersoft.jasperserver.api.metadata.common.domain.Folder;
import com.jaspersoft.jasperserver.api.metadata.common.domain.InternalURI;
import com.jaspersoft.jasperserver.api.metadata.common.domain.client.FolderImpl;
import com.jaspersoft.jasperserver.api.metadata.common.service.RepositoryService;
import com.jaspersoft.jasperserver.api.metadata.user.domain.ObjectPermission;
import com.jaspersoft.jasperserver.api.metadata.user.domain.Role;
import com.jaspersoft.jasperserver.api.metadata.user.domain.User;
import com.jaspersoft.jasperserver.api.metadata.user.service.ObjectPermissionService;
import com.jaspersoft.jasperserver.api.metadata.user.service.UserAuthorityService;
/**
* This class is useful to handle folders in the JRS Repository.
*
*/
public class FolderHelper {
private static Log log = LogFactory.getLog(FolderHelper.class);
private RepositoryService repositoryService;
private ObjectPermissionService permissionService;
private ExecutionContext ctx;
private UserAuthorityService internalUserAuthorityService;
protected static final Pattern RESOURCE_ID_INVALID_CHAR =
Pattern.compile("[^\\p{L}\\p{N}]");
protected static final String RESOURCE_ID_CHAR_REPLACEMENT = "_";
/**
* Constructor for the Folder Helper Class
* @param repositoryService
* @param permissionService
* @param internalUserAuthorityService
*/
public FolderHelper(RepositoryService repositoryService,
ObjectPermissionService permissionService,
UserAuthorityService internalUserAuthorityService) {
super();
this.repositoryService = repositoryService;
this.permissionService = permissionService;
this.internalUserAuthorityService = internalUserAuthorityService;
this.ctx = getAdminContext();
}
/**
* Set a Permission to a folder for the requested role
* @param target The InternalURI of the folder
* @param role The role expressed as String
* @param permissionType Permission type expressed as String, the available values are available in the class JasperServerAclEntry
* @return the object permission generated, already saved using the permissionService
*/
public ObjectPermission setPermissionOnFolderForRole(InternalURI target, String role, String permissionType) {
Role userRole=internalUserAuthorityService.getRole(ctx, role);
return setPermissionsToFolder(target, userRole, permissionType);
}
/**
* Set a Permission to a folder for the requested user
* @param target The InternalURI of the folder
* @param user The role expressed as String
* @param permissionType Permission type expressed as String, the available values are available in the class JasperServerAclEntry
* @return the object permission generated, already saved using the permissionService
*/
public ObjectPermission setPermissionOnFolderForUser(InternalURI target, User user, String permissionType) {
return setPermissionsToFolder(target, user, permissionType);
}
/**
* Set a Permission to a folder for the requested recipient
* @param target The InternalURI of the folder
* @param recipient The recipient of the permission, it can be a User, a Role...
* @param permissionType Permission type expressed as String, the available values are available in the class JasperServerAclEntry
* @return the object permission generated, already saved using the permissionService
*/
public ObjectPermission setPermissionsToFolder(InternalURI target, Object recipient, String permissionType) {
int permissionMask = JasperServerPermissionUtil.parsePermission(permissionType);
ObjectPermission permission = permissionService.newObjectPermission(ctx);
permission.setURI(target.getURI());
permission.setPermissionRecipient(recipient);
permission.setPermissionMask(permissionMask);
permissionService.putObjectPermission(ctx, permission);
return permission;
}
/**
* Create a new folder
* @param name Name of the folder
* @param label Label of the folder
* @param parent parent URI for the folder
* @param description Description of the folder
* @return the Folder Object for the created folder
*/
public Folder createFolder(String name, String label, String parent, String description) {
Folder folder = new FolderImpl();
folder.setName(name);
folder.setLabel(label);
folder.setParentFolder(parent);
folder.setDescription(description);
repositoryService.saveFolder(ctx, folder);
return folder;
}
public String createFolderIfNotExists(String name, String label, String parent, String description) {
String folderPath = parent + Folder.SEPARATOR + name;
if(!folderExists(folderPath)){
createFolder(name, label, parent, description);
}
return folderPath;
}
/**
* Remove all the setted up permissions on a folder.
* It retrieves only the permissions defined for the folder, not the inherited ones.
* An inherited permission is marked with a * in the JRS interfaces
* @param folder
*/
public void removeAllPermissionsFromFolder(InternalURI folder){
User currentUser = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
List listPermissions=permissionService.getEffectivePermissionsForObject(ctx, folder);
for(ObjectPermission perm:listPermissions){
log.error("deleting permission for:"+perm.getPermissionRecipient().toString());
if(!perm.getPermissionRecipient().equals(currentUser)){
int permissionMask = JasperServerPermissionUtil.parsePermission("NOTHING");
perm.setPermissionMask(permissionMask);
permissionService.putObjectPermission(ctx, perm);
}
}
}
/**
* @return the AdminContext, needed to perform some operations on folders
*/
protected ExecutionContext getAdminContext() {
ExecutionContext ctx = new ExecutionContextImpl();
List attrs = new ArrayList();
attrs.add(ObjectPermissionService.PRIVILEGED_OPERATION);
ctx.setAttributes(attrs);
return ctx;
}
/**
* @param folderPath
* @return true if the folder already exists in the repository
*/
public boolean folderExists(String folderPath){
return repositoryService.getFolder(ctx, folderPath)!=null;
}
/**
* @param inputLabel the name to set as ID
* @return the String with unallowed character replaced by _
*/
public static String getCompliantIdForResource(String inputLabel){
String id = RESOURCE_ID_INVALID_CHAR.matcher(inputLabel).replaceAll(
RESOURCE_ID_CHAR_REPLACEMENT);
return id;
}
}
package com.jaspersoft.jasperserver.api.security.externalAuth.sample.processors;
import java.util.Collections;
import java.util.Map;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.security.core.context.SecurityContextHolder;
import com.jaspersoft.jasperserver.api.metadata.common.domain.Folder;
import com.jaspersoft.jasperserver.api.metadata.common.util.RepositoryLabelIDHelper;
import com.jaspersoft.jasperserver.api.metadata.user.domain.User;
import com.jaspersoft.jasperserver.api.security.externalAuth.processors.AbstractExternalUserProcessor;
/**
* This class is useful to create a folder automatically when a user logs in and set
* its permissions according to configuration.
* It adds features to externalUserFolderProcessor (which is already provided as an example in
* the documentation).
*
*/
public class ExtendedUserFolderProcessor extends AbstractExternalUserProcessor {
private static final Logger log = LogManager.getLogger(ExtendedUserFolderProcessor.class);
// The parent folder to create user directories under. default value is root.
private String userFoldersParentDirectory = "";
// The permission for the home folder created
private String userPermissionOnFolder = "READ_WRITE_CREATE_DELETE";
// Map containing ROLE_NAME : permission_on_folder
private Map rolePermissionMap = Collections.emptyMap();
// Pattern for the folder label
private String folderLabelPattern = UserDetailPropertyKey.USERNAME.value;
// Pattern for the folder id
private String folderIdPattern = UserDetailPropertyKey.USERNAME.value;
private Boolean createParentFolder = Boolean.FALSE;
// Checks if user has a folder on his name in the configured location, if not creates
// one. The parent folder is created if not existent and requested.
@Override
public void process() {
FolderHelper helper = new FolderHelper(getRepositoryService(),
getObjectPermissionService(), getUserAuthorityService());
if (getCreateParentFolder()&&!helper.folderExists(getUserFoldersParentDirectory())){
createParentFolder(helper);
}
if (!helper.folderExists(getUserFolderPathUri())){
createUserFolder(helper);
}
}
private void createUserFolder(FolderHelper helper) {
User currentUser = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
// preparing the folder
String folderLabel = getUserFolderLabel(currentUser);
String generatedId = RepositoryLabelIDHelper.generateIdBasedOnLabel(getRepositoryService(), getUserFolderPathUri(), getUserFolderId(currentUser));
Folder folder = helper.createFolder(generatedId, folderLabel, getUserFoldersParentDirectory(), "Default user folder");
log.debug("folder "+folder.getName()+" was created with label \""+folder.getLabel()+"\" .");
// setting the permission for the user
helper.setPermissionsToFolder(folder, currentUser, getUserPermissionOnFolder());
for(String role : getRolePermissionMap().keySet()){
String permissionType = getRolePermissionMap().get(role);
helper.setPermissionOnFolderForRole(folder, role, permissionType);
}
}
private void createParentFolder(FolderHelper helper) {
// Preparing the folder
Integer lastIdx = getUserFoldersParentDirectory().lastIndexOf(Folder.SEPARATOR);
String dirName = getUserFoldersParentDirectory().substring(lastIdx+1);
String dirParentPath = getUserFoldersParentDirectory().substring(0, lastIdx);
String generatedId = RepositoryLabelIDHelper.generateIdBasedOnLabel(getRepositoryService(), dirParentPath, dirName);
Folder folder = helper.createFolder(generatedId, dirName, dirParentPath, "Container for user folders");
log.debug("folder "+folder.getName()+" was created with label \""+folder.getLabel()+"\" .");
}
private String getStringFromPattern(User currentUser, String folderId) {
String folderLabel = folderId;
folderLabel = folderLabel.replaceAll(UserDetailPropertyKey.USERNAME.value, currentUser.getUsername());
folderLabel = folderLabel.replaceAll(UserDetailPropertyKey.FULL_NAME.value, currentUser.getFullName());
folderLabel = folderLabel.replaceAll(UserDetailPropertyKey.EMAIL_ADDRESS.value, currentUser.getEmailAddress());
folderLabel = folderLabel.replaceAll(UserDetailPropertyKey.TENANT.value, currentUser.getTenantId());
return folderLabel;
}
private String getUserFolderId(User currentUser) {
return getStringFromPattern(currentUser, getFolderIdPattern());
}
private String getUserFolderLabel(User currentUser) {
return getStringFromPattern(currentUser, getFolderLabelPattern());
}
private String getUserFolderPathUri() {
User user = ((User)SecurityContextHolder.getContext().getAuthentication().getPrincipal());
String folderId = getUserFolderId(user);
return getUserFoldersParentDirectory() + Folder.SEPARATOR + FolderHelper.getCompliantIdForResource(folderId);
}
public String getUserFoldersParentDirectory() {
return userFoldersParentDirectory;
}
public void setUserFoldersParentDirectory(String userFoldersParentDirectory) {
this.userFoldersParentDirectory = userFoldersParentDirectory;
}
public Map getRolePermissionMap() {
return rolePermissionMap;
}
public void setRolePermissionMap(Map rolePermissionMap) {
this.rolePermissionMap = rolePermissionMap;
}
public String getUserPermissionOnFolder() {
return userPermissionOnFolder;
}
public void setUserPermissionOnFolder(String userPermissionOnFolder) {
this.userPermissionOnFolder = userPermissionOnFolder;
}
public String getFolderLabelPattern() {
return folderLabelPattern;
}
public void setFolderLabelPattern(String folderLabelPattern) {
this.folderLabelPattern = folderLabelPattern;
}
public String getFolderIdPattern() {
return folderIdPattern;
}
public void setFolderIdPattern(String folderIdPattern) {
this.folderIdPattern = folderIdPattern;
}
public Boolean getCreateParentFolder() {
return createParentFolder;
}
public void setCreateParentFolder(Boolean createParentFolder) {
this.createParentFolder = createParentFolder;
}
private enum UserDetailPropertyKey{
USERNAME("USERNAME"), FULL_NAME("FULL_NAME"),EMAIL_ADDRESS("EMAIL_ADDRESS"),TENANT("TENANT");
private String value;
private UserDetailPropertyKey(String value) {
this.value = value;
}
}
}
关于java - 如何获取服务器上某些子报表的ReportDesign类以进行基于scriptlet的修改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37960315/
是否可以创建一个 sql 语句来动态生成 3 行而无需任何表..这些将包括 value1 : 10 | value2: 10 value2 : 11 | value2: 11 value3 : 12
近日,葡萄城正式发布了SpreadJS最新版本 V17.1,为前端表格控件市场带来了一系列令人瞩目的新特性和功能增强。本次更新旨在进一步提升用户在计算引擎、报表生成和分析等方面的体验,为各行业的开发者
我正在使用 Visual Studio 的 Crystal 报告,我创建了一个需要有背景图像的报告。我找不到像 Microsoft Report Viewer Report 这样的背景图像的方法。有办
我正在开发一个使用 Crystal Reports 生成 pdf、excel 和 word 报告文件的大型 C# 项目。 项目位于 SVN 存储库下,我们有主干和一个单独的分支。 我们每周都会将主干合
我以正确的格式放置了我的 super 语句,但我唯一的错误是它指出类 java.lang.object 中的构造函数对象不能应用于这部分代码的给定类型: super (openFile
我正在使用 Visual Studio 2008 并希望在报告中显示以下 SQL 查询: select name, count(*) from mytable group by name; 我可以通过
我使用 C# 在我的 CR 上正确地导入了一个图像。现在我需要在同一页面上显示包含 4 种不同产品的报告,类似这样: | P1 | P2 | | P3 | P4 | 为此,我创建了一个报告并将选项 R
我正在使用 C#.net 2010,我想使用两个表创建发票。一个表 Order 包含客户订购的东西,如类别、数量、费率、总金额,另一个表 Details 包含最终支付金额的详细信息,如 Vat、Fin
我正在使用 C# 创建一个 Crystal Report,我必须在 320 个不同的参数中复制一个简单的公式,但始终具有相同的条件,如下所示: if ({Precios.AhorroE1}[1] =
我在 vs2010 中创建了一个项目,然后创建了一个已部署的安装项目。当我在我的 PC 上运行应用程序时,它显然运行良好,但对于客户端计算机,应用程序运行良好,除了 crystal报道。我制作了安装项
我正在使用 Visual Studio、.NET 创建一个使用 Crystal 报表的 Web 应用程序,除了手动拖放之外,有什么方法可以让我以有组织的方式格式化这些报表? 谢谢 最佳答案 是的,报告
我正在使用 Visual Studio 2010 创建一个使用 Crystal Reports 的 Web 应用程序。 我目前使用 odp.NET 连接到 oracle 数据库并且一切正常,当我通过
我在 Windows 窗体应用程序 C# 中有 mysql 数据库,我想使用 Crystal 报告进行报告,但我想在没有报告向导的情况下连接到数据库,因为我希望我的应用程序独立于数据库服务器地址,并且
我正在开发一个超过 200 个表的大项目,我使用 MySQL(Percona)、Java 和 Crystal Report JRC。我有一些报告非常大并且多个表之间有很多连接。在Java客户端中,我通
我有一份报告和一份带有法语国际化资源包的子报告。没有抛出任何错误或警告,但是当我使用此报告创建 pdf 时,出现奇怪的字符,因为编码错误(É 代表 é 是一个例子)。 我仍在调查那个问题,但我猜它与子
我在让 Crystal Reports 与我们的应用程序很好地协同工作时遇到了一些问题。而且我似乎找不到任何资源来回答我的问题。 基本上,我们有一个 Crystal 报表,在 Crystal 报表应用
我正在为 Winform 使用 VS 2008。我在元素中有 Crystal 报表,我想在 CSS 的帮助下对其进行格式化。 谁能给我指出正确的教程来开始这个? 最佳答案 Visual Studio
我是java和crysal报告的新手。两天以来,我尝试使用 java 和 jsf 创建 Crystal 报告 pdf。一切正常,但是当我在代码中包含参数传递时,出现错误 *HTTP Status 5
我是这个工具的新手,所以我不知道如何获取类的数据并显示在报告中。 我没有数据库,我的信息存储在类内的变量中。像这样(文件夹 Objetos): 我的程序执行以下操作:读取 XML、使用 XSD 验证、
我需要在只有一个独立数据集(未连接到任何类型的数据库)的应用程序中使用 Crystal Reports 生成报告。此外,我需要根据 DataTable 中的值生成报告。 你能帮我看看吗,我是新手。我有
我是一名优秀的程序员,十分优秀!