Commit 8b478e35 authored by Brian Long's avatar Brian Long
Browse files

Merge branch 'develop' into stable

parents 1d5fa402 bd5b2185
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@
		<dependency>
			<groupId>com.inteligr8.alfresco</groupId>
			<artifactId>aps-public-rest-api</artifactId>
			<version>2.0.11</version>
			<version>2.0.14</version>
		</dependency>
		<dependency>
			<groupId>com.inteligr8.alfresco</groupId>
+31 −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.maven.aps.modeling.crawler;

/**
 * An interface for APS template export transformation implementations.
 * 
 * An APS template is a JSON file.
 * 
 * @author brian@inteligr8.com
 */
public interface ApsTemplateCrawlable {

	/**
	 * @return A file transformer for APS template JSON files.
	 */
	ApsFileTransformer getTemplateJsonTransformer();

}
+74 −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.maven.aps.modeling.crawler;

import java.io.File;
import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A class that implements a APS App export crawler.  The crawler does not
 * directly perform any transformations.  Those are handled through a callback.
 * 
 * @author brian@inteligr8.com
 */
public class ApsTemplateCrawler {

	private final Logger logger = LoggerFactory.getLogger(ApsTemplateCrawler.class);
	private final File templateDirectory;
	private final boolean failOnIntegrityViolation;
	
	/**
	 * @param apsAppName A name for the APS App.
	 * @param apsAppDirectory A directory to the unpacked APS App export.
	 * @param failOnIntegrityViolation true to fail on file integrity issues; false to log warnings.
	 */
	public ApsTemplateCrawler(File apsTemplateDirectory, boolean failOnIntegrityViolation) {
		this.templateDirectory = apsTemplateDirectory;
		this.failOnIntegrityViolation = failOnIntegrityViolation;
	}
	
	/**
	 * @param crawlable A crawlable implementation; the callback for potential transformations.
	 * @throws IOException A file access exception occurred.
	 */
	public void execute(ApsTemplateCrawlable crawlable) throws IOException {
		this.logger.info("Crawling APS templates ...");
		
		this.crawlTemplates(crawlable.getTemplateJsonTransformer());
	}
	
	protected void crawlTemplates(ApsFileTransformer transformer) throws IOException {
		for (File templateFile : this.templateDirectory.listFiles()) {
		    if (!templateFile.getName().endsWith(".json"))
		        continue;
		    
			this.logger.trace("Transforming template: {}", templateFile);
			
			try {
			    transformer.transformFile(templateFile, null, null);
	        } catch (IllegalArgumentException | IllegalStateException ie) {
	            if (this.failOnIntegrityViolation) {
	                throw ie;
	            } else {
	                this.logger.warn(ie.getMessage());
	            }
	        }
		}
	}

}
+18 −0
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@
 */
package com.inteligr8.maven.aps.modeling.goal;

import java.util.List;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.settings.Server;
@@ -21,6 +23,7 @@ import org.apache.maven.settings.Server;
import com.inteligr8.alfresco.activiti.ApsClientJerseyConfiguration;
import com.inteligr8.alfresco.activiti.ApsClientJerseyImpl;
import com.inteligr8.alfresco.activiti.ApsPublicRestApiJerseyImpl;
import com.inteligr8.alfresco.activiti.model.Tenant;

/**
 * This class adds APS addressbility to extending goals.
@@ -129,4 +132,19 @@ public abstract class ApsAddressibleGoal extends DisablableGoal {
		return this.api;
	}
    
    /**
     * This method makes the appropriate service calls to find the first APS
     * tenant ID from the configured APS service.
     * 
     * This method does not cache the result.
     * 
     * @return An APS tenant ID; null only if there are no tenants.
     */
    protected Long findTenantId() {
        List<Tenant> tenants = this.getApsApi().getAdminApi().getTenants();
        if (tenants == null || tenants.isEmpty())
            return null;
        return tenants.iterator().next().getId();
    }

}
+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ import com.inteligr8.alfresco.activiti.model.Tenant;
 * 
 * @author brian@inteligr8.com
 */
public abstract class ApsAppAccessibleGoal extends ApsAddressibleGoal {
public abstract class ApsAppAddressibleGoal extends ApsAddressibleGoal {

	@Parameter( property = "aps-model.appName", required = true )
	protected String apsAppName;
Loading