#1 2018-02-13 02:07:29

shivasakthi18
Member
Registered: 2018-02-13

file purging via SQL queries or API

Hi,

The main issue with report server is arising when there is storage of large volume of files. So I am trying to delete files from team space periodically.

Following is the step i am following now.

delete from RS_EXEC_REPORT_AS_FILE_REF where id=?;
delete from RS_TS_DISK_GENERAL_REFERENCE where id=?;
delete from RS_TS_DISK_NODE where entity_id=?;
delete from RS_COMPILED_REPORT where entity_id in (?);

Is there any other good way to do it ....?

Thanks,
Sivasakthi.

Offline

#2 2018-02-13 07:59:09

eduardo
Administrator
Registered: 2016-11-01
Website

Re: file purging via SQL queries or API

Hi Sivasakthi,

you should not delete/modify data directly with SQL, as you may miss dependencies. Only reportserver and/or reportserver scripting should be used for this purpose. In the contrary, this may have unexpected results. Check the scripting guide for this: https://reportserver.net/en/guides/script/main/
You may also want to check the API documentation downloadable from https://sourceforge.net/projects/dw-rs/files/src/3.0/. There, you can find a list of services, a list of entities and a list of hooks along with the javadocs.

Regards,
Eduardo

Offline

#3 2018-02-13 08:07:18

shivasakthi18
Member
Registered: 2018-02-13

Re: file purging via SQL queries or API

Hi Admin,

It's a useful information, Can somebody help me to delete all CSV file older than 1 or 2 days in an automated way...?

Thanks,
Sivasakthi.

Last edited by shivasakthi18 (2018-02-21 14:15:13)

Offline

#4 2018-03-05 23:09:46

shivasakthi18
Member
Registered: 2018-02-13

Re: file purging via SQL queries or API

Hi,

It seems there isn't enough documentation on scripting side to delete files from team space. Please update if any.

Thanks,
Sivasakthi.

Offline

#5 2018-03-08 15:05:26

eduardo
Administrator
Registered: 2016-11-01
Website

Re: file purging via SQL queries or API

Hi shivasakthi18,

You can write a script for this purpose.
We have the java class attached which can be written equivalently in groovy. This class performs a similar purpose:

- it finds users which have not logged in for a given time
- it deactivates these users
The method to be called is the run() method.

For your purpose, you can write an analogous script. You can schedule it to execute e.g. every night. In order to find out the relevant information on your reports you can use these methods:

Find out created date:
report.getCreatedOn();

Find out last changed date:
report.getLastUpdated();

Delete a report:
reportService.remove(report);
(using net.datenwerke.rs.core.service.reportmanager.ReportService).

import java.util.Collection;

import org.apache.commons.configuration.Configuration;

import net.datenwerke.rs.core.service.genrights.access.AccessRsSecurityTarget;
import net.datenwerke.rs.core.service.mail.MailService;
import net.datenwerke.rs.core.service.mail.MailTemplate;
import net.datenwerke.rs.core.service.mail.SimpleMail;
import net.datenwerke.rs.passwordpolicy.service.activateuser.ActivateUserModule;
import net.datenwerke.rs.utils.config.ConfigService;
import net.datenwerke.security.service.security.SecurityService;
import net.datenwerke.security.service.security.SecurityServiceSecuree;
import net.datenwerke.security.service.security.entities.Ace;
import net.datenwerke.security.service.security.entities.AceAccessMap;
import net.datenwerke.security.service.security.entities.Acl;
import net.datenwerke.security.service.usermanager.UserManagerService;
import net.datenwerke.security.service.usermanager.UserPropertiesService;
import net.datenwerke.security.service.usermanager.entities.User;


public class UserDeactivator {
	
	// 3 months in milliseconds
	private final long interval = 7884000000L;
	
	private UserPropertiesService userPropertiesService;
	private SecurityService securityService;
	private MailService mailService;
	private ConfigService configService;
	private UserManagerService userManagerService;
	
	public UserDeactivator(
			UserPropertiesService userPropertiesService,
			MailService mailService,
			SecurityService securityService,
			ConfigService configService,
			UserManagerService userManagerService) {
		
		this.userPropertiesService = userPropertiesService;
		this.securityService = securityService;
		this.mailService = mailService;
		this.configService = configService;
		this.userManagerService = userManagerService;
	}
	
	public void run() {
		
		Collection<User> allUser = userManagerService.getAllUsers();
		long today = System.currentTimeMillis();
		long lastLogin;
		
		for(User u : allUser) {
			lastLogin = Long.parseLong(userPropertiesService.getPropertyValue(u,Constants.LAST_LOGIN_DATE)); 
			if(today - lastLogin > interval) {
				deactivate(u); 
				//sendMail(u);
			}
		}

		
	}
	private void deactivate(User u) {
		Class target = AccessRsSecurityTarget.class;
		Acl acl = securityService.loadGenericTarget(target).getAcl();
		Ace ace = securityService.createACE(target);
		ace.setFolk(u);
		AceAccessMap aceMap = ace.getAccessMap(SecurityServiceSecuree.SECUREE_ID);
				
		aceMap.clearAccess();

		acl.addAce(ace);
		securityService.merge(acl);
		securityService.persist(acl);
		
	}

	private void sendMail(User u) {	
		
		
		/* fill email temlate*/
		MailTemplate template = new MailTemplate();
		
		Configuration config = configService.getConfig(ActivateUserModule.CONFIG_FILE);
		template.setMessageTemplate(config.getString(ActivateUserModule.PROPERTY_EMAIL_TEXT));
		template.setSubjectTemplate(config.getString(ActivateUserModule.PROPERTY_EMAIL_SUBJECT));
		//template.setDataMap(replacements);
		
		/* create and send message */
		SimpleMail mailMessage = mailService.newTemplateMail(template);
		mailMessage.setToRecipients(u.getEmail());
		mailService.sendMail(mailMessage);
	}
	

}

Note: The "Constants" class is just a class defining some constants, in this case, the name of the user property used for last login.

Regards,
Eduardo

Offline

#6 2019-01-30 05:40:57

shivasakthi18
Member
Registered: 2018-02-13

Re: file purging via SQL queries or API

Hi Eduardo,

I achieved extracting reportserver encapsulated data and purging it periodically without scripting, its working good.,

Thanks for your timely help.
Sivasakthi.

Last edited by shivasakthi18 (2019-01-30 05:42:08)

Offline

Board footer

Powered by FluxBB