@Before public void setUp() throws Exception { repository = mock(IUnifiedRepository.class); session = mock(IPentahoSession.class); when(session.getName()).thenReturn("test"); PentahoSessionHolder.setSession(session); userSettings = new HashMap<String, Serializable>() { { put(USER_SETTING_NAME_1, USER_SETTING_VALUE_1); put(UserSettingService.SETTING_PREFIX + COMMON_SETTING_NAME, COMMON_USER_SETTING_VALUE); put(USER_SETTING_NAME_2, USER_SETTING_VALUE_2); put(UserSettingService.SETTING_PREFIX + USER_SETTING_NAME_3, USER_SETTING_VALUE_3); } }; globalSettings = new HashMap<String, Serializable>() { { put(GLOBAL_SETTING_NAME_1, GLOBAL_SETTING_VALUE_1); put( UserSettingService.SETTING_PREFIX + COMMON_SETTING_NAME, COMMON_GLOBAL_SETTING_VALUE); put(GLOBAL_SETTING_NAME_2, GLOBAL_SETTING_VALUE_2); put(UserSettingService.SETTING_PREFIX + GLOBAL_SETTING_NAME_3, GLOBAL_SETTING_VALUE_3); } }; when(repository.getFileMetadata(eq(USER_FOLDER_ID))).thenReturn(userSettings); when(repository.getFileMetadata(eq(TENANT_FOLDER_ID))).thenReturn(globalSettings); final RepositoryFile tenantRepositoryFile = mock(RepositoryFile.class); when(tenantRepositoryFile.getId()).thenReturn(TENANT_FOLDER_ID); when(repository.getFile(eq(ClientRepositoryPaths.getEtcFolderPath()))) .thenReturn(tenantRepositoryFile); final RepositoryFile userRepositoryFile = mock(RepositoryFile.class); when(userRepositoryFile.getId()).thenReturn(USER_FOLDER_ID); when(repository.getFile(eq(ClientRepositoryPaths.getUserHomeFolderPath(session.getName())))) .thenReturn(userRepositoryFile); securityHelper = mock(ISecurityHelper.class); when(securityHelper.runAsSystem(any(Callable.class))) .thenAnswer( new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { final Callable callable = (Callable) invocation.getArguments()[0]; if (callable != null) { return callable.call(); } return null; } }); SecurityHelper.setMockInstance(securityHelper); userSettingService = new UserSettingService(repository); userSettingService.init(session); }
@Override public List<StringKeyStringValueDto> getFileMetadata(final String fileId) { final Map<String, Serializable> metadataMap = repo.getFileMetadata(fileId); final List<StringKeyStringValueDto> fileMetadataMap = new ArrayList<StringKeyStringValueDto>(metadataMap.size()); for (final String key : metadataMap.keySet()) { fileMetadataMap.add(new StringKeyStringValueDto(key, metadataMap.get(key).toString())); } return fileMetadataMap; }
public void fileCreated(String filePath) { IUnifiedRepository repository = PentahoSystem.get(IUnifiedRepository.class); RepositoryFile outputFile = repository.getFile(filePath); if (outputFile != null) { Map<String, Serializable> fileMetadata = repository.getFileMetadata(outputFile.getId()); RepositoryFile inputFile = repository.getFile(inputFilePath); if (inputFile != null) { fileMetadata.put(PentahoJcrConstants.PHO_CONTENTCREATOR, inputFile.getId()); repository.setFileMetadata(outputFile.getId(), fileMetadata); } } }
/** Performs the process of reloading the domain information from the repository */ private void internalReloadDomains() { lock.writeLock().lock(); try { metadataMapping.reset(); // Reload the metadata about the metadata (that was fun to say) final List<RepositoryFile> children = repository.getChildren(getMetadataDir().getId(), "*"); if (logger.isTraceEnabled()) { logger.trace("\tFound " + children.size() + " files in the repository"); } for (final RepositoryFile child : children) { if (getAclHelper().canAccess(child, READ)) { // Get the metadata for this file final Map<String, Serializable> fileMetadata = repository.getFileMetadata(child.getId()); if (fileMetadata == null || StringUtils.isEmpty((String) fileMetadata.get(PROPERTY_NAME_DOMAIN_ID))) { if (logger.isWarnEnabled()) { logger.warn( messages.getString( "PentahoMetadataDomainRepository.WARN_0001_FILE_WITHOUT_METADATA", child.getName())); } continue; } final String domainId = (String) fileMetadata.get(PROPERTY_NAME_DOMAIN_ID); final String type = (String) fileMetadata.get(PROPERTY_NAME_TYPE); final String locale = (String) fileMetadata.get(PROPERTY_NAME_LOCALE); if (logger.isTraceEnabled()) { logger.trace( "\tprocessing file [type=" + type + " : domainId=" + domainId + " : locale=" + locale + "]"); } // Save the data in the map if (StringUtils.equals(type, TYPE_DOMAIN)) { metadataMapping.addDomain(domainId, child); } else if (StringUtils.equals(type, TYPE_LOCALE)) { metadataMapping.addLocale(domainId, locale, child); } } } needToReload = false; } finally { lock.writeLock().unlock(); } }
protected String toString(final RepositoryFile file) { try { final Map<String, Serializable> fileMetadata = repository.getFileMetadata(file.getId()); return "[type=" + fileMetadata.get(PROPERTY_NAME_TYPE) + " : domain=" + fileMetadata.get(PROPERTY_NAME_DOMAIN_ID) + " : locale=" + fileMetadata.get(PROPERTY_NAME_LOCALE) + " : filename=" + file.getName() + "]"; } catch (Throwable ignore) { // ignore } return "null"; }
public RepositoryFileTreeDto getTree( final String path, final int depth, final String filter, final boolean showHidden) { RepositoryFileTree tree = repo.getTree(path, depth, filter, showHidden); // Filter system folders from non-admin users. // PDI uses this web-service and system folders must be returned to admin repository database // connections. List<RepositoryFileTree> files = new ArrayList<RepositoryFileTree>(); IAuthorizationPolicy policy = PentahoSystem.get(IAuthorizationPolicy.class); boolean isAdmin = policy.isAllowed(AdministerSecurityAction.NAME); for (RepositoryFileTree file : tree.getChildren()) { Map<String, Serializable> fileMeta = repo.getFileMetadata(file.getFile().getId()); boolean isSystemFolder = fileMeta.containsKey(IUnifiedRepository.SYSTEM_FOLDER) ? (Boolean) fileMeta.get(IUnifiedRepository.SYSTEM_FOLDER) : false; if (!isAdmin && isSystemFolder) { continue; } files.add(file); } tree = new RepositoryFileTree(tree.getFile(), files); return tree != null ? repositoryFileTreeAdapter.marshal(tree) : null; }