AEM Workflow: getModel() method is throwing null value - aem

I've created a new workflow model in the workflow console and trying to access it using a service. From the jsp I'm passing the workflow name as /etc/workflow/models/DeleteNode/jcr:content/model, followed the format mentioned in the AEM docs. But the WorkFlowModel is throwing null value while I try to get the model from the path that I've passed.
below is the service that I've written:
package com.aem.sample.workflow;
import java.util.Calendar;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.StringWriter;
import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;
import java.io.InputStream;
import javax.jcr.Repository;
import javax.jcr.SimpleCredentials;
import javax.jcr.Node;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.jackrabbit.commons.JcrUtils;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import javax.jcr.RepositoryException;
import org.apache.felix.scr.annotations.Reference;
import org.apache.jackrabbit.commons.JcrUtils;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.jcr.api.SlingRepository;
import javax.jcr.Session;
import javax.jcr.Node;
//Adobe CQ Workflow APIs
import com.day.cq.workflow.model.WorkflowModel ;
import com.day.cq.workflow.WorkflowService ;
import com.day.cq.workflow.WorkflowSession;
import com.day.cq.workflow.exec.WorkflowData;
//Sling Imports
import org.apache.sling.api.resource.ResourceResolverFactory ;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.Resource;
//This is a component so it can provide or consume services
#Component
#Service
public class InvokeAEMWorkflowImp implements InvokeAEMWorkflow {
#Reference
private WorkflowService workflowService;
private Session session;
#Reference
private ResourceResolverFactory resolverFactory;
#Override
public String StartWorkflow(String workflowName, String workflowContent) {
try
{
//Invoke the adaptTo method to create a Session
ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);
session = resourceResolver.adaptTo(Session.class);
//Create a workflow session
WorkflowSession wfSession = workflowService.getWorkflowSession(session);
// Get the workflow model
WorkflowModel wfModel = wfSession.getModel(workflowName);
// Get the workflow data
// The first param in the newWorkflowData method is the payloadType. Just a fancy name to let it know what type of workflow it is working with.
WorkflowData wfData = wfSession.newWorkflowData("JCR_PATH", workflowContent);
// Run the Workflow.
wfSession.startWorkflow(wfModel, wfData);
return workflowName +" has been successfully invoked on this content: "+workflowContent ;
}
catch(Exception e)
{
e.printStackTrace();
}
return null;
}
}

Related

No Results are shown on Eclipse Console when Karate Runner file is run as Junit Test but when file called in Command line using mvn test it works

I have the below Karate Runner File Content. When I executed this file on Eclipse, nothing is shownup on Console. Can Someone please help on this issue for me.
package com.accounting.apirunner;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import com.intuit.karate.Results;
import com.intuit.karate.Runner;
import com.intuit.karate.junit5.Karate;
import cucumber.api.CucumberOptions;
import net.masterthought.cucumber.Configuration;
import net.masterthought.cucumber.ReportBuilder;
#CucumberOptions(features = { "classpath:Accountspayables", "classpath:Accountsreceivables", "classpath:company",
"classpath:generalLedger", "classpath: SpendManagement" }, tags = {
"~#ignore" }, plugin = { "pretty", "html:target/cucumber-html-reports" }, monochrome = true)
public class TestCaseRunner {
#BeforeClass
public static void beforeClass() throws Exception {
System.setProperty("karate.env", "SAT");
#Test
public void testParallel() {
Results results = Runner.path("classpath:Accountspayables", "classpath:Accountsreceivables",
"classpath:company", "classpath:generalLedger", "classpath: SpendManagement").tags("~#ignore")
.parallel(1);
generateReport(results.getReportDir());
assertTrue(results.getErrorMessages(), results.getFailCount() == 0);
String karateOutputPath = "target/surefire-reports";
}
public static void generateReport(String karateOutputPath) {
Collection<File> jsonFiles = FileUtils.listFiles(new File(karateOutputPath), new String[] { "json" }, true);
List<String> jsonPaths = new ArrayList(jsonFiles.size());
for (File file : jsonFiles) {
jsonPaths.add(file.getAbsolutePath());
}
Configuration config = new Configuration(new File("target"), "Accounting XMLGW Regression Test Suite");
ReportBuilder reportBuilder = new ReportBuilder(jsonPaths, config);
reportBuilder.generateReports();
}
}
And no Executions shown up on Junit Explorer.

when() not working in RestAssured using eclipse

I am trying to run the following code with eclipse but it will give me the error: "The method when() is undefined for the type LastLabTest". I have imported the libraries but still it gives me that error. I am using eclipse with junit5.
import io.restassured.RestAssured;
import io.restassured.RestAssured.*;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.filter.log.RequestLoggingFilter;
import io.restassured.filter.log.ResponseLoggingFilter;
import io.restassured.http.ContentType;
import io.restassured.matcher.RestAssuredMatchers.*;
import io.restassured.specification.RequestSpecification;
import org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.BeforeClass;
import org.junit.jupiter.api.Test;
class LastLabTest {
private RequestSpecification specification;
#BeforeClass
public void inItSpec() {
specification = new RequestSpecBuilder()
.setContentType(ContentType.JSON)
.setBaseUri("http://openlibrary.org/")
.addFilter(new RequestLoggingFilter())
.addFilter(new ResponseLoggingFilter())
.build();
}
#Test
public void getByName() {
when().get("https://swapi.co/api/people/1")
.then().log().all()
.statusCode(200)
.and()
.body("name", equals("Luke Skywalker"));
}
}
The keyword static is missing in the line
import io.restassured.RestAssured.*;
=>
import static io.restassured.RestAssured.*;
keyword static is missing in import io.restassured.RestAssured.;
correct : import static io.restassured.RestAssured.;

View resolving does not always work

I have a Spring Boot (V 1.3.5) Web Application with JSPs packaged as jar. The views are located in src/main/resources/META-INF/resources/WEB-INF/views.
See http://hillert.blogspot.lu/2016/03/spring-boot-with-jsp-in-executable-jar.html on that subject.
This works well on my Fedora dev. workstation, and as well on a colleague's with Windows 7, both using Eclipse Mars.
But on another Windows 8 PC, the same sourcecode run in Eclipse or STS, produces a 404 because no view can be found, and this starts aching my head seriously.
I append my configuration class here, maybe someone has an idea what could go wrong here.
package our.base.package;
import java.util.Locale;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Profile;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
import org.springframework.orm.jpa.vendor.HibernateJpaSessionFactoryBean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.i18n.CookieLocaleResolver;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
#Configuration
#EnableScheduling
#EnableCaching
//#EnableWebMvc
#ComponentScan(basePackages = { "our.base.package" })
public class SpringConfigRootApplication extends WebMvcConfigurerAdapter {
#Bean
public LocaleResolver localeResolver() {
final CookieLocaleResolver slr = new CookieLocaleResolver();
slr.setCookieMaxAge(86400 * 365 * 5);
slr.setCookieName("lang");
slr.setDefaultLocale(Locale.GERMAN);
return slr;
}
#Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
final LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
lci.setParamName("lang");
lci.setIgnoreInvalidLocale(true);
return lci;
}
#Override
public void addInterceptors(final InterceptorRegistry registry) {
registry.addInterceptor(localeChangeInterceptor());
}
#Override
public void addViewControllers(final ViewControllerRegistry registry) {
registry.addViewController("/login").setViewName("login");
}
#Bean
public InternalResourceViewResolver getInternalResourceViewResolver() {
final InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
resolver.setRequestContextAttribute("requestContext");
resolver.setExposeContextBeansAsAttributes(true);
return resolver;
}
#Bean(initMethod = "init", destroyMethod = "shutdown")
#Order(value = Ordered.LOWEST_PRECEDENCE)
public Application application() {
return new Application();
}
}

How to integrate OSM tiles

I am developing an app in which i want offline map so am using osmdroid and slf4j libs.I have map tiles which i get using the Mobile Atlas Creator. How to integrate those tiles in java code ?
MainActvity is:
package com.example.osmofflinemap;
import org.osmdroid.DefaultResourceProxyImpl;
import org.osmdroid.ResourceProxy;
import org.osmdroid.api.IMapController;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.tileprovider.tilesource.XYTileSource;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.ScaleBarOverlay;
import org.osmdroid.views.overlay.SimpleLocationOverlay;
import android.support.v4.app.Fragment;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
public class MainActivity extends Activity {
private MapView mapView;
private MapController mapController;
private ScaleBarOverlay mScaleBarOverlay;
private SimpleLocationOverlay mMyLocationOverlay;
MyItemizedOverlay myItemizedOverlay = null;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView map = (MapView) findViewById(R.id.mapview);
map.setTileSource(new XYTileSource("MapQuest",
ResourceProxy.string.mapquest_osm, 0, 18, 256, ".jpg", new String[] {
"/sdcard/osmdroid/MapQuest/4/10/6",
"/sdcard/osmdroid/MapQuest/4/10/7",
"/sdcard/osmdroid/MapQuest/4/11/6",
"/sdcard/osmdroid/MapQuest/4/11/7"}));
map.setBuiltInZoomControls(true);
map.setMultiTouchControls(true);
map.setUseDataConnection(false); //optional, but a good way to prevent loading from the network and test your zip loading.
IMapController mapController = map.getController();
mapController.setZoom(4);
GeoPoint startPoint = new GeoPoint(18.533333, 73.866667);
mapController.setCenter(startPoint);
}
}

jersey 2 library response.getEntity not exist what should I use instead

my code
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package beans;
import clients.NewJerseyClient;
import entities.ReservationItem;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.ws.rs.core.GenericType;
import parameters.ReservationParam;
import org.glassfish.jersey.client.ClientResponse;
/**
*
* #author subhi2
*/
#ManagedBean
#SessionScoped
public class PageController implements Serializable {
public String moveToPage2() {
NewJerseyClient client = new NewJerseyClient();
ClientResponse response = client.findInsertedReservationItem(ClientResponse.class, "22", "2010-07-26T11:15:51", "2014-07-26T11:15:51");
GenericType<List<ReservationItem>> genericType = new GenericType<List<ReservationItem>>() {
};
// Returns an ArrayList of Players from the web service
List<ReservationItem> data = new ArrayList<ReservationItem>();
data = (response.getEntity(genericType));
return data.toString();
}
}
the line
data = (response.getEntity(genericType));
cause the error
this code was working with old jersey but now what should I do to solve this error ?
You can change response.getEntity(genericType) by response.readEntity(genericType)
For what you are asking I've replaced this
response.getEntity(String.class);
by this
response.getEntityStream().toString();
But there could be another problems related with Jersey 2, I could get it working by replacing these imports
import jersey.spi.container.servlet.ServletContainer;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
By these
import org.glassfish.jersey.servlet.ServletContainer;
import org.glassfish.jersey.client.ClientResponse;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
and in the code (as I was using Jetty) I had to replace this
servletHolder.setInitParameter("com.sun.jersey.config.property.packages",
"resources");
by this
servletHolder.setInitParameter("jersey.config.server.provider.packages",
"resources");
and this
WebResource webResource = client.resource("http://url_u_want_to_connect");
ClientResponse response = webResource.accept("application/json")
by this
WebTarget webTarget = client.target("http://url_u_want_to_connect");
ClientResponse response = webTarget.request("application/json")
Finally here is a link for "latest" docs (It's about Jersey 2.x, at 2013)
https://jersey.java.net/documentation/latest/user-guide.html