Commit 755271cc authored by Brian Long's avatar Brian Long
Browse files

initial checkin

parents
Loading
Loading
Loading
Loading

.gitignore

0 → 100644
+13 −0
Original line number Diff line number Diff line
# Maven
target
pom.xml.versionsBackup

# Eclipse
.settings
.project
.classpath

# Visual Studio Code
.factorypath
.vscode

pom.xml

0 → 100644
+88 −0
Original line number Diff line number Diff line
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	
	<groupId>com.inteligr8.alfresco</groupId>
	<artifactId>bulk-platform-module</artifactId>
	<version>1.0-SNAPSHOT</version>
	<packaging>jar</packaging>
	
	<name>bulk ACS Platform Module</name>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<maven.compiler.source>8</maven.compiler.source>
		<maven.compiler.target>8</maven.compiler.target>

		<alfresco.sdk.version>4.2.0</alfresco.sdk.version>
		<alfresco.platform.version>6.2.0-ga</alfresco.platform.version>
	</properties>

	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.alfresco</groupId>
				<artifactId>acs-community-packaging</artifactId>
				<version>${alfresco.platform.version}</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

	<dependencies>
		<!-- Very popular, but not required, dependency -->
		<!-- Provided as an example -->
		<dependency>
			<groupId>org.alfresco</groupId>
			<artifactId>alfresco-repository</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>io.swagger</groupId>
			<artifactId>swagger-jaxrs</artifactId>
			<version>1.6.2</version>
			<scope>provided</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>io.repaint.maven</groupId>
				<artifactId>tiles-maven-plugin</artifactId>
				<version>2.26</version>
				<extensions>true</extensions>
				<configuration>
					<tiles>
						<!-- Documentation: https://bitbucket.org/inteligr8/ootbee-beedk/src/stable/beedk-acs-platform-self-rad-tile -->
						<tile>com.inteligr8.ootbee:beedk-acs-platform-self-rad-tile:[1.0.0,2.0.0)</tile>
						<!-- Documentation: https://bitbucket.org/inteligr8/ootbee-beedk/src/stable/beedk-acs-platform-module-tile -->
						<tile>com.inteligr8.ootbee:beedk-acs-platform-module-tile:[1.0.0,2.0.0)</tile>
						<!-- Documentation: https://bitbucket.org/inteligr8/ootbee-beedk/src/stable/beedk-acs-platform-self-it-tile
						<tile>com.inteligr8.ootbee:beedk-acs-platform-self-it-tile:[1.0.0,2.0.0)</tile> -->
					</tiles>
				</configuration>
			</plugin>
		</plugins>
	</build>
	
	<repositories>
		<repository>
			<id>inteligr8-releases</id>
			<url>http://repos.inteligr8.com/nexus/repository/inteligr8-public</url>
		</repository>
		<repository>
			<id>alfresco-public</id>
			<url>https://artifacts.alfresco.com/nexus/content/groups/public</url>
		</repository>
	</repositories>

	<pluginRepositories>
		<pluginRepository>
			<id>inteligr8-releases</id>
			<url>http://repos.inteligr8.com/nexus/repository/inteligr8-public</url>
		</pluginRepository>
	</pluginRepositories>
</project>
 No newline at end of file

rad.ps1

0 → 100644
+74 −0
Original line number Diff line number Diff line

function discoverArtifactId {
	$script:ARTIFACT_ID=(mvn -q -Dexpression=project"."artifactId -DforceStdout help:evaluate)
}

function rebuild {
	echo "Rebuilding project ..."
	mvn process-classes
}

function start_ {
	echo "Rebuilding project and starting Docker containers to support rapid application development ..."
	mvn -Drad process-classes
}

function start_log {
	echo "Rebuilding project and starting Docker containers to support rapid application development ..."
	mvn -Drad "-Ddocker.showLogs" process-classes
}

function stop_ {
	discoverArtifactId
	echo "Stopping Docker containers that supported rapid application development ..."
	docker container ls --filter name=${ARTIFACT_ID}-*
	echo "Stopping containers ..."
	docker container stop (docker container ls -q --filter name=${ARTIFACT_ID}-*)
	echo "Removing containers ..."
	docker container rm (docker container ls -aq --filter name=${ARTIFACT_ID}-*)
}

function tail_logs {
	param (
		$container
	)
	
	discoverArtifactId
	docker container logs -f (docker container ls -q --filter name=${ARTIFACT_ID}-${container})
}

function list {
	discoverArtifactId
	docker container ls --filter name=${ARTIFACT_ID}-*
}

switch ($args[0]) {
	"start" {
		start_
	}
	"start_log" {
		start_log
	}
	"stop" {
		stop_
	}
	"restart" {
		stop_
		start_
	}
	"rebuild" {
		rebuild
	}
	"tail" {
		tail_logs $args[1]
	}
	"containers" {
		list
	}
	default {
		echo "Usage: .\rad.ps1 [ start | start_log | stop | restart | rebuild | tail {container} | containers ]"
	}
}

echo "Completed!"

rad.sh

0 → 100644
+71 −0
Original line number Diff line number Diff line
#!/bin/sh

discoverArtifactId() {
	ARTIFACT_ID=`mvn -q -Dexpression=project.artifactId -DforceStdout help:evaluate`
}

rebuild() {
	echo "Rebuilding project ..."
	mvn process-classes
}

start() {
	echo "Rebuilding project and starting Docker containers to support rapid application development ..."
	mvn -Drad process-classes
}

start_log() {
	echo "Rebuilding project and starting Docker containers to support rapid application development ..."
	mvn -Drad -Ddocker.showLogs process-classes
}

stop() {
	discoverArtifactId
	echo "Stopping Docker containers that supported rapid application development ..."
	docker container ls --filter name=${ARTIFACT_ID}-*
	echo "Stopping containers ..."
	docker container stop `docker container ls -q --filter name=${ARTIFACT_ID}-*`
	echo "Removing containers ..."
	docker container rm `docker container ls -aq --filter name=${ARTIFACT_ID}-*`
}

tail_logs() {
	discoverArtifactId
	docker container logs -f `docker container ls -q --filter name=${ARTIFACT_ID}-$1`
}

list() {
	discoverArtifactId
	docker container ls --filter name=${ARTIFACT_ID}-*
}

case "$1" in
	start)
		start
		;;
	start_log)
		start_log
		;;
	stop)
		stop
		;;
	restart)
		stop
		start
		;;
	rebuild)
		rebuild
		;;
	tail)
		tail_logs $2
		;;
	containers)
		list
		;;
	*)
		echo "Usage: ./rad.sh [ start | start_log | stop | restart | rebuild | tail {container} | containers ]"
		exit 1
esac

echo "Completed!"
+136 −0
Original line number Diff line number Diff line
/*
 * This program 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 3 of the License, or (at your
 * option) any later version.
 * 
 * This program 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 General Public License for
 * more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
package com.inteligr8.alfresco.bulk;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import org.alfresco.model.ContentModel;
import org.alfresco.repo.policy.BehaviourFilter;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.MimetypeService;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.apache.tika.Tika;
import org.apache.tika.config.TikaConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.extensions.webscripts.AbstractWebScript;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.inteligr8.alfresco.bulk.model.ContentDataBody;

public abstract class AbstractNodesWebScript extends AbstractWebScript {
    
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    
    @Value("${inteligr8.bulk.enableTika:false}")
    private boolean enableTika;
    
    @Value("${inteligr8.bulk.allowOctetStream:false}")
    protected boolean allowOctetStream;

    @Autowired
    protected ContentService contentService;

    @Autowired
    protected DictionaryService dictionaryService;
    
    @Autowired
    protected MimetypeService mimeTypeService;
    
    @Autowired
    protected NamespaceService namespaceService;

    @Autowired
    protected NodeService nodeService;
    
    @Autowired
    protected BehaviourFilter behaviorFilter;

    @Autowired
    protected TransactionService txService;
    
    protected final ObjectMapper om = new ObjectMapper();
    
    protected final Collection<MediaType> jsonMediaTypes =
    		MediaType.parseMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON_VALUE, "applicatin/*+json"));
    
    protected List<ContentDataBody> wrapContents(ContentDataBody contentData, List<ContentDataBody> contents) {
    	List<ContentDataBody> allcontents = new ArrayList<>(contents == null ? 1 : (contents.size() + 1));
    	if (contentData != null)
    		allcontents.add(contentData);
    	if (contents != null)
    		allcontents.addAll(contents);
    	return allcontents;
    }
    
    protected void validateRequest(List<?> nodes) {
    	if (nodes == null || nodes.isEmpty())
    		throw new WebScriptException(HttpStatus.BAD_REQUEST.value(), "At least one node is required");
    }
    
    protected String determineMimeType(QName contentPropName, ContentReader creader, String name) {
    	if (this.enableTika) {
    		this.logger.trace("Using Tika to detect the MIME type: {} => {}", creader.getContentUrl(), name);
    		
    		try {
	    		InputStream istream = creader.getContentInputStream();
	    		try {
	    			Tika tika = new Tika(TikaConfig.getDefaultConfig());
	    			String mimeType = tika.detect(istream, name);
	        		this.logger.trace("Tika detected MIME type: {} => {}", creader.getContentUrl(), mimeType);
	        		
	    			if (!MediaType.APPLICATION_OCTET_STREAM_VALUE.equals(mimeType))
	    				return mimeType;
	    		} finally {
	    			istream.close();
	    		}
    		} catch (IOException ie) {
    			this.logger.warn("Tika MIME detection failed: {}: {}", creader.getContentUrl(), ie.getMessage());
    		}
    	}
    	
    	if (!contentPropName.equals(ContentModel.PROP_CONTENT)) {
    		this.logger.debug("Unable to auto-detect a content property other than the default 'cm:content': {}", contentPropName);
			return null;
    	}
		
		int pos = name.lastIndexOf('.');
		if (pos < 0) {
    		this.logger.debug("Unable to auto-detect a MIME type without a filename extension: {}", name);
			return null;
		}
			
		String extension = name.substring(pos+1);
		String mimeType = this.mimeTypeService.getMimetype(extension);
		this.logger.debug("Detected file extension and MIME type: {} => {}", extension, mimeType);
		return mimeType;
    }
    
}
Loading