Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions celements-filebase/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>com.celements</groupId>
<artifactId>celements</artifactId>
<version>7.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>celements-filebase</artifactId>
<version>7.1-SNAPSHOT</version>
<description>Open-Celements Filebase</description>
<dependencies>
<dependency>
<groupId>com.celements</groupId>
<artifactId>celements-spring-security</artifactId>
<version>7.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.celements</groupId>
<artifactId>celements-model</artifactId>
<version>7.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.celements</groupId>
<artifactId>celements-core</artifactId>
<version>7.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.celements</groupId>
<artifactId>celements-user-manager</artifactId>
<version>7.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.celements</groupId>
<artifactId>celements-wiki-manager</artifactId>
<version>7.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<scm>
<connection>scm:git:git@github.com:celements/celements-base.git</connection>
<developerConnection>scm:git:git@github.com:celements/celements-base.git</developerConnection>
<url>https://github.com/celements/celements-base/celements-filebase</url>
<tag>HEAD</tag>
</scm>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.celements.filebase;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.xwiki.configuration.ConfigurationSource;

import com.celements.filebase.exceptions.NoValidFileBaseImplFound;
import com.google.common.base.Strings;
import com.xpn.xwiki.web.Utils;

@Component
public class FileBaseAccessService implements IFileBaseAccessRole {

private static final Logger LOGGER = LoggerFactory.getLogger(FileBaseAccessService.class);

private final ConfigurationSource configuration;

public FileBaseAccessService(ConfigurationSource configuration) {
this.configuration = configuration;
}

@Override
public IFileBaseServiceRole getInstance() throws NoValidFileBaseImplFound {
String fileBaseImplKey = getFileBaseImplKey();
if (!Strings.isNullOrEmpty(fileBaseImplKey) && !"default".equals(fileBaseImplKey)) {
IFileBaseServiceRole theFileBaseImpl = Utils.getComponent(IFileBaseServiceRole.class,
fileBaseImplKey);
if (theFileBaseImpl != null) {
return theFileBaseImpl;
}
}
LOGGER.error("Failed to get valid FileBase implementation instance.");
throw new NoValidFileBaseImplFound(fileBaseImplKey);
}

private String getFileBaseImplKey() {
return configuration.getProperty(FILEBASE_SERVICE_IMPL_CFG,
SingleDocFileBaseService.FILEBASE_SINGLE_DOC);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.celements.filebase;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.xwiki.model.reference.AttachmentReference;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.script.service.ScriptService;

import com.celements.filebase.cmd.TokenBasedUploadCommand;
import com.celements.filebase.exceptions.FileBaseLoadException;
import com.celements.filebase.exceptions.FileNotExistsException;
import com.celements.filebase.matcher.IAttachmentMatcher;
import com.celements.rights.access.exceptions.NoAccessRightsException;
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.api.Attachment;
import com.xpn.xwiki.doc.XWikiAttachment;

@Component("filebase")
public class FileBaseScriptService implements ScriptService {

private static final Logger LOGGER = LoggerFactory.getLogger(FileBaseScriptService.class);

private final IAttachmentServiceRole attachmentService;
private final IFileBaseServiceRole filebaseService;
private final TokenBasedUploadCommand tokenbasedUploadCmd;

@Inject
public FileBaseScriptService(IAttachmentServiceRole attachmentService,
@Named(SingleDocFileBaseService.FILEBASE_SINGLE_DOC) IFileBaseServiceRole filebaseService,
TokenBasedUploadCommand tokenbasedUploadCmd) {
this.attachmentService = attachmentService;
this.filebaseService = filebaseService;
this.tokenbasedUploadCmd = tokenbasedUploadCmd;
}

public String clearFileName(String fileName) {
return attachmentService.clearFileName(fileName);
}

public int tokenBasedUpload(DocumentReference attachToDocRef, String fieldName,
String userToken) {
return tokenBasedUpload(attachToDocRef, fieldName, userToken, false);
}

public int tokenBasedUpload(DocumentReference attachToDocRef, String fieldName, String userToken,
Boolean createIfNotExists) {
try {
return tokenbasedUploadCmd.tokenBasedUploadDocRef(attachToDocRef, fieldName,
userToken, createIfNotExists);
} catch (XWikiException exp) {
LOGGER.error("token based attachment upload failed: ", exp);
}
return 0;
}

public int deleteAttachmentList(List<AttachmentReference> attachmentRefList) {
return attachmentService.deleteAttachmentList(attachmentRefList);
}

public boolean existsFileNameEqual(String filename) throws FileBaseLoadException {
return filebaseService.existsFileNameEqual(filename);
}

public Attachment getFileNameEqual(String filename) throws FileBaseLoadException {
try {
XWikiAttachment xwikiAtt = filebaseService.getFileNameEqual(filename);
return attachmentService.getApiAttachment(xwikiAtt);
} catch (FileNotExistsException e) {
LOGGER.trace("Filebase could not find file [{}]", filename);
} catch (NoAccessRightsException nare) {
LOGGER.info("User {} was refused {} access on file base document {}", nare.getUser(),
nare.getExpectedAccessLevel(), nare.getEntityRef());
}
return null;
}

public List<Attachment> getFilesNameMatch(IAttachmentMatcher attMatcher)
throws FileBaseLoadException {
List<XWikiAttachment> xwikiAttList = filebaseService.getFilesNameMatch(attMatcher);
List<Attachment> attList = new ArrayList<>();
for (XWikiAttachment xwikiAtt : xwikiAttList) {
try {
attList.add(attachmentService.getApiAttachment(xwikiAtt));
} catch (NoAccessRightsException nare) {
LOGGER.info("User {} was refused {} access on file base document {}", nare.getUser(),
nare.getExpectedAccessLevel(), nare.getEntityRef());
}
}
return attList;
}
}
Loading