Java Code Examples for freemarker.ext.beans.StringModel

The following examples show how to use freemarker.ext.beans.StringModel. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: camel-quarkus   Source File: UpdateDocExtensionsListMojo.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Object exec(List arguments) throws TemplateModelException {
    if (arguments.size() != 1) {
        throw new TemplateModelException("Expected one argument for getDocLink(); found " + arguments.size());
    }
    ArtifactModel<?> model = (ArtifactModel<?>) DeepUnwrap.unwrap((StringModel) arguments.get(0));
    final String artifactIdBase = CqUtils.getArtifactIdBase(model);
    final String extensionPageName = artifactIdBase + ".adoc";
    final Path extensionPagePath = extensionsDocPath.resolve(extensionPageName);
    if (!Files.exists(extensionPagePath)) {
        throw new IllegalStateException(
                "File " + extensionPagePath + " must exist to be able to refer to it from " + extensionListPath
                        + ".\nYou may need to add\n\n    org.apache.camel.quarkus:camel-quarkus-maven-plugin:update-extension-doc-page\n\nmojo in "
                        + artifactIdBase + " runtime module");
    }
    return "xref:extensions/" + extensionPageName;
}
 
Example 2
Source Project: kaif   Source File: RelativeTime.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Object exec(List arguments) throws TemplateModelException {
  if (arguments.size() < 1) {
    throw new TemplateModelException("require an Instant as argument");
  }
  if (arguments.size() > 2) {
    throw new TemplateModelException("too many arguments");
  }
  PrettyTime prettyTime = new PrettyTime(Environment.getCurrentEnvironment().getLocale());
  // only support day unit now
  if (arguments.size() == 2 && arguments.get(1).toString().equals("Day")) {
    List<TimeUnit> units = prettyTime.getUnits()
        .stream()
        .filter(timeUnit -> timeUnit.getMillisPerUnit() > new Day().getMillisPerUnit())
        .collect(Collectors.toList());
    units.forEach(prettyTime::removeUnit);
  }

  StringModel stringModel = (StringModel) arguments.get(0);
  Instant instant = (Instant) stringModel.getAdaptedObject(Instant.class);
  return prettyTime.format(Date.from(instant));
}
 
Example 3
Source Project: windup   Source File: GetClassificationForFile.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
    ExecutionStatistics.get().begin(NAME);
    if (arguments.size() != 1)
    {
        throw new TemplateModelException("Error, method expects one argument (" + FileModel.class.getSimpleName() + ")");
    }
    StringModel stringModelArg = (StringModel) arguments.get(0);
    FileModel fileModel = (FileModel) stringModelArg.getWrappedObject();
    
    ClassificationService classificationService = new ClassificationService(context);
    Iterable<ClassificationModel> result = classificationService.getClassifications(fileModel);
    
    ExecutionStatistics.get().end(NAME);
    return result;
}
 
Example 4
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
    ExecutionStatistics.get().begin(NAME);
    if (arguments.size() != 1)
    {
        throw new TemplateModelException("Error, method expects one argument (ProjectModel)");
    }
    StringModel stringModelArg = (StringModel) arguments.get(0);
    if (stringModelArg == null)
    {
        throw new IllegalArgumentException("FreeMarker Method " + NAME + " called with null project model");
    }
    ProjectModel projectModel = (ProjectModel) stringModelArg.getWrappedObject();
    ApplicationReportIndexModel index = service.getApplicationReportIndexForProjectModel(projectModel);
    if (index == null)
    {
        LOG.warning("Could not find an application index for project model: " + projectModel.getName() + " (Vertex ID: "
                    + projectModel.getElement().id() + ")");
    }
    ExecutionStatistics.get().end(NAME);
    return index;
}
 
Example 5
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
    ExecutionStatistics.get().begin(NAME);

    // Function arguments
    ProjectModel projectModel = null;

    // The project. May be null -> all input applications.
    if (arguments.size() >= 1) {
        StringModel projectArg = (StringModel) arguments.get(0);
        projectModel = (ProjectModel) projectArg.getWrappedObject();
    }

    MatrixAndAggregated result = computeProjectAndTagsMatrix(this.graphContext, projectModel);

    ExecutionStatistics.get().end(NAME);
    return result;
}
 
Example 6
Source Project: windup   Source File: GetNumberOfLibrariesMethod.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
    ExecutionStatistics.get().begin(NAME);

    // Function arguments
    ProjectModel projectModel = null;

    // The project. May *not* be null. All input applications should be passed into this method individually
    if (arguments.size() >= 1) {
        StringModel projectArg = (StringModel) arguments.get(0);
        projectModel = (ProjectModel) projectArg.getWrappedObject();
    }

    if (projectModel == null) {
        String errorMessage = "GetNumberOfLibrariesMethod: No project present to count libraries";
        throw new WindupException(errorMessage);
    }

    Integer result = countLibrariesInModel(this.graphContext, projectModel);

    ExecutionStatistics.get().end(NAME);
    return result;
}
 
Example 7
Source Project: windup   Source File: SortTechUsageStatsMethod.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
    ExecutionStatistics.get().begin(NAME);

    // Function arguments
    if (arguments.size() > 1)
        throw new TemplateModelException("Expected 0 or 1 argument - project.");

    // The project. May be null -> count from all applications.
    ProjectModel application = null;
    if (arguments.size() == 1)
    {
        StringModel projectArg = (StringModel) arguments.get(0);
        if (null != projectArg)
            application = (ProjectModel) projectArg.getWrappedObject();
    }

    TechReportService.TechStatsMatrix matrix = techReportService.getTechStatsMap(application);

    ExecutionStatistics.get().end(NAME);
    return matrix;
}
 
Example 8
Source Project: windup   Source File: IsFileADirectoryMethod.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
    ExecutionStatistics.get().begin(NAME);

    // Function arguments
    FileModel fileModel = null;

    // The file may *not* be null.
    if (arguments.size() >= 1) {
        StringModel fileArg = (StringModel) arguments.get(0);
        fileModel = (FileModel) fileArg.getWrappedObject();
    }

    if (fileModel == null) {
        String errorMessage = "IsFileADirectoryMethod: No file present to check";
        throw new WindupException(errorMessage);
    }

    Boolean result = fileModel.isDirectory();

    ExecutionStatistics.get().end(NAME);
    return result;
}
 
Example 9
Source Project: windup   Source File: FormatRule.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
    ExecutionStatistics.get().begin(NAME);
    if (arguments.size() != 1)
    {
        throw new TemplateModelException("Error, method expects one argument (Rule)");
    }
    StringModel stringModelArg = (StringModel) arguments.get(0);
    Rule rule = (Rule) stringModelArg.getWrappedObject();

    String result = RuleUtils.ruleToRuleContentsString(rule, 0);

    ExecutionStatistics.get().end(NAME);
    return result;
}
 
Example 10
Source Project: windup   Source File: ProjectModelToSha1.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
	Object result = null;
    ExecutionStatistics.get().begin(NAME);
    if (arguments.size() != 1)
    {
        throw new TemplateModelException("Error, method expects one argument (ProjectModel)");
    }
    StringModel stringModelArg = (StringModel) arguments.get(0);
    if (stringModelArg == null)
    {
        throw new IllegalArgumentException("FreeMarker Method " + NAME + " called with null project model");
    }
    ProjectModel projectModel = (ProjectModel) stringModelArg.getWrappedObject();
    if(projectModel.getRootFileModel() instanceof IdentifiedArchiveModel) {
    	result = projectModel.getRootFileModel().getSHA1Hash();
    }
    ExecutionStatistics.get().end(NAME);

    return result;
}
 
Example 11
Source Project: enkan   Source File: FreemarkerTemplateEngine.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public Object createFunction(Function<List, Object> func) {
    return (TemplateMethodModelEx) arguments ->
            func.apply((List)arguments.stream().map(arg -> {
                if (arg instanceof BeanModel) {
                    return ((StringModel) arg).getWrappedObject();
                } else {
                    return arg;
                }
            }).collect(Collectors.toList()));
}
 
Example 12
Source Project: ogham   Source File: SpringBeansTemplateHashModelEx.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public KeyValuePairIterator keyValuePairIterator() throws TemplateModelException {
	return new KeyValuePairIterator() {
		private int currentIdx = 0;

		@Override
		public KeyValuePair next() throws TemplateModelException {
			if (!hasNext()) {
				throw new NoSuchElementException();
			}
			KeyValuePair pair = new KeyValuePair() {

				@Override
				public TemplateModel getValue() throws TemplateModelException {
					String name = applicationContext.getBeanDefinitionNames()[currentIdx];
					return new LazySpringBeanAccessModel(applicationContext, beansWrapper, name);
				}

				@Override
				public TemplateModel getKey() throws TemplateModelException {
					return new StringModel(applicationContext.getBeanDefinitionNames()[currentIdx], beansWrapper);
				}
			};
			currentIdx++;
			return pair;
		}

		@Override
		public boolean hasNext() throws TemplateModelException {
			return currentIdx < applicationContext.getBeanDefinitionCount();
		}
	};
}
 
Example 13
@Override
  public int doStartTag() throws JspException {
ServletRequest request = this.pageContext.getRequest();
RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
try {
	ExecutorBeanContainer ebc = (ExecutorBeanContainer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_EXECUTOR_BEAN_CONTAINER);
	TemplateModel templateModel = ebc.getTemplateModel();
	if (!(templateModel instanceof AllHttpScopesHashModel)) {
		return EVAL_BODY_INCLUDE;
	}
	AllHttpScopesHashModel hashModel = (AllHttpScopesHashModel) templateModel;
	Object object = this.pageContext.getAttribute(this.getValueName());
	if (null == object) {
		Environment environment = Environment.getCurrentEnvironment();
		if (null != environment) {
			Object wrapper = environment.getVariable(this.getValueName());
			if (null != wrapper) {
				if (wrapper instanceof StringModel) {
					object = ((StringModel) wrapper).getWrappedObject();
				} else {
					object = wrapper;
				}
			}
		}
	}
	if (null != object) {
		hashModel.put(this.getVar(), object);
	}
      } catch (Throwable t) {
      	_logger.error("error in doStartTag", t);
          throw new JspException("Error during tag initialization", t);
      }
      return EVAL_BODY_INCLUDE;
  }
 
Example 14
private String extractAttribute() throws JspException {
if (null == this.getVar()) {
	return null;
}
String objectToString = null;
try {
	Object object = this.pageContext.getAttribute(this.getVar());
	if (null == object) {
		Environment environment = Environment.getCurrentEnvironment();
		if (null != environment) {
			Object wrapper = environment.getVariable(this.getVar());
			if (null != wrapper) {
				if (wrapper instanceof StringModel) {
					object = ((StringModel) wrapper).getWrappedObject();
				} else {
					object = wrapper;
				}
			}
		}
	}
	if (null != object) {
		objectToString = object.toString();
	}
      } catch (Throwable t) {
      	_logger.error("error extracting freemarker attribute", t);
          throw new JspException("Error extracting freemarker attribute", t);
      }
return objectToString;
  }
 
Example 15
Source Project: cms   Source File: TestWBFreeMarkerModuleDirective.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void test_execute_catch_exception()
{
	Environment envMock = PowerMock.createMock(Environment.class);
	TemplateModel[] loopVars = null;
	TemplateDirectiveBody directiveBodyMock = null;
	
	Map params = new HashMap();
	String name = "testXYZ";
	StringModel nameModel = new StringModel(name, new DefaultObjectWrapper() );
	params.put("name", nameModel);

	try
	{
		
		WPBPageModule pageModuleMock = PowerMock.createMock(WPBPageModule.class);		
		WPBPageModulesCache pageModuleCacheMock = PowerMock.createMock(WPBPageModulesCache.class);
		EasyMock.expect(pageModuleCacheMock.getByExternalKey(name)).andThrow(new WPBIOException(""));
		
		EasyMock.expect(cacheInstancesMock.getPageModuleCache()).andReturn(pageModuleCacheMock);

		EasyMock.replay(cacheInstancesMock, templateEngineMock, envMock, pageModuleMock, pageModuleCacheMock);
		
		FreeMarkerModuleDirective templateDirective = new FreeMarkerModuleDirective();
		Whitebox.setInternalState(templateDirective, "templateEngine",templateEngineMock);
		Whitebox.setInternalState(templateDirective, "cacheInstances",cacheInstancesMock);
		PowerMock.suppressMethod(FreeMarkerModuleDirective.class, "copyParams");
		templateDirective.execute(envMock, params, loopVars, directiveBodyMock);
		
		assertTrue(false);		
	} catch (Exception e)
	{
		assertTrue(e instanceof TemplateModelException);
	}
}
 
Example 16
Source Project: cms   Source File: TestWBFreeMarkerModuleDirective.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void test_execute_noPageModule()
{
	Environment envMock = PowerMock.createMock(Environment.class);
	TemplateModel[] loopVars = null;
	TemplateDirectiveBody directiveBodyMock = null;
	
	Map params = new HashMap();
	String name = "testXYZ";
	StringModel nameModel = new StringModel(name, new DefaultObjectWrapper() );
	params.put("name", nameModel);

	try
	{

		WPBPageModule pageModuleMock = PowerMock.createMock(WPBPageModule.class);		
		WPBPageModulesCache pageModuleCacheMock = PowerMock.createMock(WPBPageModulesCache.class);
		EasyMock.expect(pageModuleCacheMock.getByExternalKey(name)).andReturn(null);
		
		EasyMock.expect(cacheInstancesMock.getPageModuleCache()).andReturn(pageModuleCacheMock);

		EasyMock.replay(cacheInstancesMock, templateEngineMock, envMock, pageModuleMock, pageModuleCacheMock);
		
		FreeMarkerModuleDirective templateDirective = new FreeMarkerModuleDirective();
		Whitebox.setInternalState(templateDirective, "templateEngine",templateEngineMock);
		Whitebox.setInternalState(templateDirective, "cacheInstances",cacheInstancesMock);
		PowerMock.suppressMethod(FreeMarkerModuleDirective.class, "copyParams");
		templateDirective.execute(envMock, params, loopVars, directiveBodyMock);
	
		assertTrue(false);
		
	} catch (Exception e)
	{
		assertTrue(e instanceof TemplateModelException);
	}
}
 
Example 17
Source Project: windup   Source File: GetTechnologyTagsForFile.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
    ExecutionStatistics.get().begin(NAME);
    if (arguments.size() != 1)
    {
        throw new TemplateModelException("Error, method expects one argument (" + FileModel.class.getSimpleName() + ")");
    }
    StringModel stringModelArg = (StringModel) arguments.get(0);
    FileModel fileModel = (FileModel) stringModelArg.getWrappedObject();
    Iterable<TechnologyTagModel> result = new TechnologyTagService(this.context).findTechnologyTagsForFile(fileModel);
    ExecutionStatistics.get().end(NAME);
    return result;
}
 
Example 18
Source Project: windup   Source File: GetProjectTraversalMethod.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object exec(List arguments) throws TemplateModelException
{
    ExecutionStatistics.get().begin(NAME);
    if (arguments.size() < 1)
    {
        throw new TemplateModelException("Error, method expects at least one argument (" + ProjectModel.class.getSimpleName() + ")");
    }
    StringModel stringModelArg = (StringModel) arguments.get(0);
    ProjectModel projectModel = (ProjectModel) stringModelArg.getWrappedObject();

    String traversalStrategyString = ALL;
    if (arguments.size() > 1)
        traversalStrategyString = ((SimpleScalar)arguments.get(1)).getAsString();

    TraversalStrategy traversalStrategy;
    if (traversalStrategyString == null)
        traversalStrategyString = ALL;
    switch (traversalStrategyString)
    {
        case ONLY_ONCE: traversalStrategy = new OnlyOnceTraversalStrategy(); break;
        case SHARED:    traversalStrategy = new SharedLibsTraversalStrategy(); break;
        default:
            Logger.getLogger(GetProjectTraversalMethod.class.getName()).warning("Unknown strategy name: " + traversalStrategyString);
        case ALL: traversalStrategy = new AllTraversalStrategy(); break;
    }

    ProjectModelTraversal traversal = new ProjectModelTraversal(projectModel, traversalStrategy);
    ExecutionStatistics.get().end(NAME);
    return traversal;
}
 
Example 19
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
    ExecutionStatistics.get().begin(NAME);
    if (arguments.size() != 1)
    {
        throw new TemplateModelException("Error, method expects one argument (" + ProjectModelTraversal.class.getSimpleName() + ")");
    }
    StringModel stringModelArg = (StringModel) arguments.get(0);
    ProjectModelTraversal projectTraversal = (ProjectModelTraversal) stringModelArg.getWrappedObject();
    Iterable<TechnologyTagModel> result = new TechnologyTagService(this.context).findTechnologyTagsForProject(projectTraversal);
    ExecutionStatistics.get().end(NAME);
    return result;
}
 
Example 20
@Override
public Object exec(List arguments) throws TemplateModelException
{
    ExecutionStatistics.get().begin(NAME);
    if (arguments.size() < 1)
    {
        throw new TemplateModelException("Error, method expects at least one argument (" + ProjectModel.class.getSimpleName() + ")");
    }
    StringModel stringModelArg = (StringModel) arguments.get(0);
    ProjectModelTraversal traversal = (ProjectModelTraversal) stringModelArg.getWrappedObject();
    ArchiveSHA1ToFilePathMapper mapper = new ArchiveSHA1ToFilePathMapper(traversal);

    ExecutionStatistics.get().end(NAME);
    return mapper;
}
 
Example 21
Source Project: windup   Source File: GetProblemSummariesMethod.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object exec(List arguments) throws TemplateModelException
{
    if (arguments.isEmpty())
        throw new TemplateModelException("Method " + getMethodName() + " requires the following parameters (GraphRewrite event, ProjectModel project, Set<String> includeTags, Set<String> excludeTags)");

    // Gets the graph rewrite event
    final GraphRewrite event = (GraphRewrite)((StringModel)arguments.get(0)).getWrappedObject();

    // Get the project if one was passed in
    final ProjectModel projectModel;

    StringModel projectModelArg = (StringModel) arguments.get(1);
    if (projectModelArg == null)
        projectModel = null;
    else
        projectModel = (ProjectModel) projectModelArg.getWrappedObject();

    Set<String> includeTags = FreeMarkerUtil.simpleSequenceToSet((SimpleSequence) arguments.get(2));
    Set<String> excludeTags = FreeMarkerUtil.simpleSequenceToSet((SimpleSequence) arguments.get(3));

    Set<ProjectModel> projectModels = getProjects(projectModel);
    Map<IssueCategoryModel, List<ProblemSummary>> problemSummariesOriginal
            = ProblemSummaryService.getProblemSummaries(event.getGraphContext(), projectModels, includeTags, excludeTags);

    // Convert the keys to String to make Freemarker happy
    Comparator<IssueCategoryModel> severityComparator = new IssueCategoryModel.IssueSummaryPriorityComparator();
    Map<IssueCategoryModel, List<ProblemSummary>> problemSummaries = new TreeMap<>(severityComparator);
    problemSummaries.putAll(problemSummariesOriginal);

    Map<String, List<ProblemSummary>> primarySummariesByString = new LinkedHashMap<>(problemSummariesOriginal.size());
    for (Map.Entry<IssueCategoryModel, List<ProblemSummary>> entry : problemSummaries.entrySet())
    {
        String severityString = entry.getKey() == null ? null : entry.getKey().getName();
        primarySummariesByString.put(severityString, entry.getValue());
    }

    return primarySummariesByString;
}
 
Example 22
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
    ExecutionStatistics.get().begin(NAME);
    if (arguments.size() != 1)
        throw new TemplateModelException("Error, method expects one argument (" + FileModel.class.getSimpleName() + ")");

    StringModel stringModelArg = (StringModel) arguments.get(0);
    FileModel fileModel = (FileModel) stringModelArg.getWrappedObject();
    Set<String> tags = this.findTagsFromFileClassificationsAndHints(fileModel);
    ExecutionStatistics.get().end(NAME);
    return tags;
}
 
Example 23
Source Project: windup   Source File: IsRulePhaseMethod.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
    if (arguments.size() != 1)
    {
        throw new TemplateModelException(
                    "Error, method expects one argument (Object)");
    }
    StringModel stringModel = (StringModel) arguments.get(0);
    Object object = stringModel.getWrappedObject();
    return object instanceof RulePhase;
}
 
Example 24
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
    ExecutionStatistics.get().begin(NAME);
    if (arguments.size() != 1)
    {
        throw new TemplateModelException("Error, method expects one argument (FileModel)");
    }
    StringModel stringModelArg = (StringModel) arguments.get(0);
    FileModel fileModel = (FileModel) stringModelArg.getWrappedObject();
    SourceReportModel result = sourceReportService.getSourceReportForFileModel(fileModel);
    ExecutionStatistics.get().end(NAME);
    return result;
}
 
Example 25
Source Project: windup   Source File: IsReportableFile.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
    ExecutionStatistics.get().begin(NAME);
    try
    {
        if (arguments.size() != 3)
        {
            throw new TemplateModelException("Error, method expects one argument (FileModel, includeTags:Set<String>, excludeTags:Set<String>)");
        }
        StringModel stringModelArg = (StringModel) arguments.get(0);
        FileModel fileModel = (FileModel) stringModelArg.getWrappedObject();

        Set<String> includeTags = FreeMarkerUtil.simpleSequenceToSet((SimpleSequence) arguments.get(1));
        Set<String> excludeTags = FreeMarkerUtil.simpleSequenceToSet((SimpleSequence) arguments.get(2));

        SourceReportModel result = sourceReportService.getSourceReportForFileModel(fileModel);

        if (result == null)
            return false;

        return TagUtil.hasHintsOrClassificationsWithRelevantTags(result.getSourceFileModel(), includeTags, excludeTags);
    }
    finally
    {
        ExecutionStatistics.get().end(NAME);
    }
}
 
Example 26
Source Project: windup   Source File: Sha1HexMethod.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public String exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
    if (arguments.size() != 1)
    {
        throw new TemplateModelException(
                    "Error, method expects one argument (FileModel)");
    }
    StringModel stringModel = (StringModel) arguments.get(0);
    FileModel fileModel = (FileModel) stringModel.getWrappedObject();
    return !fileModel.isDirectory() ? fileModel.getSHA1Hash() : DigestUtils.sha1Hex(fileModel.getFileName());
}
 
Example 27
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
    Object result = null;

    ExecutionStatistics.get().begin(NAME);
    if (arguments.size() != 1)
    {
        throw new TemplateModelException("Error, method expects one argument (ProjectModel)");
    }
    StringModel stringModelArg = (StringModel) arguments.get(0);
    if (stringModelArg == null)
    {
        throw new IllegalArgumentException("FreeMarker Method " + NAME + " called with null project model");
    }
    ProjectModel projectModel = (ProjectModel) stringModelArg.getWrappedObject();

    if (projectModel.getRootFileModel() instanceof ArchiveModel)
    {
        result = ((ArchiveModel) projectModel.getRootFileModel()).getOrganizationModels();
    }

    ExecutionStatistics.get().end(NAME);
    
    if(result == null)
    {
        result = new ArrayList<>();
    }
    return result;
}
 
Example 28
Source Project: windup   Source File: GetEffortForFile.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
    ExecutionStatistics.get().begin(NAME);
    if (arguments.size() != 1)
    {
        throw new TemplateModelException("Error, method expects one argument (FileModel)");
    }
    StringModel fileModelArg = (StringModel) arguments.get(0);
    FileModel fileModel = (FileModel) fileModelArg.getWrappedObject();

    Object result = classificationService.getMigrationEffortPoints(fileModel) + inlineHintService.getMigrationEffortPoints(fileModel);
    ExecutionStatistics.get().end(NAME);
    return result;
}
 
Example 29
Source Project: windup   Source File: IsTagUnderTagMethod.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
    ExecutionStatistics.get().begin(NAME);

    // Function arguments
    if (arguments.size() < 2) {
        throw new TemplateModelException("Expected 2 or 3 arguments - a subsector tag, a row tag and optionally, a project.");
    }

    StringModel tag1Arg = (StringModel) arguments.get(0);
    TagModel subTag = (TagModel) tag1Arg.getWrappedObject();

    StringModel tag2Arg = (StringModel) arguments.get(1);
    TagModel maybeSuperTag = (TagModel) tag2Arg.getWrappedObject();

    // The project. May be null -> count from all applications.
    boolean countIfSame = false;
    if (arguments.size() >= 3)
    {
        BooleanModel countRootArg = (BooleanModel) arguments.get(2);
        if (null != countRootArg)
            countIfSame = countRootArg.getAsBoolean();
    }

    boolean isUnder = new TagGraphService(this.graphContext).isTagUnderTag(subTag, maybeSuperTag, countIfSame);

    ExecutionStatistics.get().end(NAME);
    return isUnder;
}
 
Example 30
Source Project: windup   Source File: GetRuleExecutionResults.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
    ExecutionStatistics.get().begin(NAME);
    if (arguments.size() != 1)
    {
        throw new TemplateModelException("Error, method expects one argument (AbstractRuleProvider)");
    }
    StringModel stringModelArg = (StringModel) arguments.get(0);
    AbstractRuleProvider ruleProvider = (AbstractRuleProvider) stringModelArg.getWrappedObject();
    List<RuleExecutionInformation> result = RuleExecutionResultsListener.instance(this.event).getRuleExecutionInformation(ruleProvider);
    ExecutionStatistics.get().end(NAME);
    return result;
}