Components details are not getting logged in my database when unpublishing the page using Tridion Deployer extension - tridion

I am trying to add the unpublished components entry in my custom storage extension. We know that we don't have any base class in Tridion for ComponentUndeploy as we have for deploy "ComponentDeploy", so I am trying to use ComponentPresentationUndeploy class to track the components which are getting and below is sample code how I am trying to track.
package com.tridion.custom.extensions;
import com.tridion.broker.StorageException;
import com.tridion.configuration.Configuration;
import com.tridion.configuration.ConfigurationException;
import com.tridion.deployer.DeploymentHandler;
import com.tridion.deployer.ProcessingException;
import com.tridion.deployer.Processor;
import com.tridion.deployer.modules.ComponentPresentationUndeploy;
import com.tridion.storage.ComponentMeta;
import com.tridion.storage.StorageManagerFactory;
import com.tridion.storage.StorageTypeMapping;
import com.tridion.storage.dao.ItemDAO;
import com.tridion.storage.dao.ItemTypeSelector;
import com.tridion.storage.dao.PublishAction;
import com.tridion.storage.dao.PublishActionDAO;
import com.tridion.storage.mapper.MapperFactory;
import com.tridion.transport.transportpackage.ComponentPresentationKey;
import com.tridion.transport.transportpackage.ProcessorInstructions;
import com.tridion.transport.transportpackage.TransportPackage;
import com.tridion.util.TCDURI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import java.util.Iterator;
public class SearchComponentUndeployer extends ComponentPresentationUndeploy {
private static Logger log = LoggerFactory
.getLogger(SearchComponentUndeployer.class);
public SearchComponentUndeployer(Configuration paramConfiguration,
Processor paramProcessor) throws ConfigurationException {
super(paramConfiguration, paramProcessor);
}
#SuppressWarnings("rawtypes")
public void process(TransportPackage paramTransportPackage) throws ProcessingException
{
ProcessorInstructions localProcessorInstructions = paramTransportPackage.getProcessorInstructions();
try
{
Iterator localIterator = localProcessorInstructions.getArguments();
while (localIterator.hasNext())
{
Object localObject = localIterator.next();
if (localObject instanceof ComponentPresentationKey)
{
ComponentPresentationKey localComponentPresentationKey = (ComponentPresentationKey) localObject;
long[] arrayOfLong = new long[2];
arrayOfLong[0] = localComponentPresentationKey.getComponentKey().getId().getItemId();
arrayOfLong[1] = localComponentPresentationKey.getTemplateKey().getId().getItemId();
int PubID = localComponentPresentationKey.getComponentKey().getId().getPublicationId();
String tcmID = Integer.toString(localComponentPresentationKey.getComponentKey().getId().getItemId());
log.info("SearchComponentUndeployer -PubID" + PubID);
log.info("SearchComponentUndeployer -tcmID" + tcmID);
ItemDAO itemDAO = ((ItemDAO) StorageManagerFactory.getDAO(PubID, StorageTypeMapping.COMPONENT_META));
log.info("SearchComponentUndeployer -itemDAO"+ itemDAO.getStorageId());
ComponentMeta compObject = (ComponentMeta) MapperFactory.mapItemMetaInstance(itemDAO.findByPrimaryKey(PubID, localComponentPresentationKey.getComponentKey().getId().getItemId(),ItemTypeSelector.COMPONENT));
log.info("SearchComponentUndeployer -compObject"+ compObject.getTitle());
String formatTCMID = String.format("tcm:%d-%s-64", PubID,tcmID);
log.info("SearchComponentUndeployer - formatTCMID -"+ formatTCMID);
String strIgnorePubIds = "232,481";
String strPubId = Integer.toString(PubID);
Date lastPublishedDate = compObject.getLastPublishDate();
String schemaID = Integer.toString(compObject.getSchemaId());
if (!strIgnorePubIds.contains(strPubId))
{
PublishAction publishAction = new PublishAction();
publishAction.setAction("DEL");
publishAction.setTcmUri(formatTCMID);
publishAction.setItemType(16);
publishAction.setPublicationID(PubID);
publishAction.setLastPublishedDate(lastPublishedDate);
publishAction.setSchemaID(schemaID);
PublishActionDAO publishActionDAO = (PublishActionDAO) StorageManagerFactory.getDefaultDAO("PublishAction");
log.debug("SearchComponentUndeployer Going to Store bean -" + publishAction.toString());
publishAction = publishActionDAO.store(publishAction);
log.debug("SearchComponentUndeployer Stored bean -" + publishAction);
}
DeploymentHandler.undeploy(new TCDURI(PubID, 73014444080L, arrayOfLong));
}
}
}
catch (StorageException e)
{
log.error("Could not undeploy component presentation", e);
}
}
}
Any idea why I am not getting any entry for components in my database
Edit: Added sample code from PageUndeploy implementation done by me:
Object argument = iterator.next();
if (argument instanceof PageKey)
{
PageKey pageKey = (PageKey) argument;
TCDURI pageMetaURI = new TCDURI(pageKey.getId() .getPublicationId(), 1168231104576L, pageKey.getId().getItemId());
PageMeta pageMeta = this.pageMetaHome.findByPrimaryKey(pageMetaURI.getPublicationId(),(int) pageMetaURI.getItemId());
if (pageMeta == null)
{
DeploymentHandler.undeploy(pageMetaURI);
}
else
{
//Here I need to loop for componentpresentation and get component object
}
}

You can try this as I just taken class name from your input
List<ComponentPresentationMeta> lstCompObjects= pageMeta.getComponentPresentationMetas();
if(lstCompObjects != null && !lstCompObjects.isEmpty())
{
for(ComponentPresentationMeta compMeta : lstCompObjects)
{
String compID = Integer.toString(compMeta.getComponentId());
ItemDAO itemDAO = ((ItemDAO) StorageManagerFactory.getDAO(compMeta.getPublicationId(), StorageTypeMapping.COMPONENT_META));
ComponentMeta compObject = (ComponentMeta) MapperFactory.mapItemMetaInstance(itemDAO.findByPrimaryKey(compMeta.getPublicationId(), compMeta.getComponentId(),ItemTypeSelector.COMPONENT));
PublishAction compPublishAction = new PublishAction();
compPublishAction.setAction("DEL");
compPublishAction.setTcmUri(compID);
compPublishAction.setItemType(16);
compPublishAction.setPublicationID(compMeta.getPublicationId());
compPublishAction.setLastPublishedDate(compObject.getLastPublicationDate());
compPublishAction.setSchemaID(Integer.toString(compObject.getSchemaId()));
compPublishAction = publishActionDAO.store(compPublishAction);
}
}

Related

Quarkus and reactive datasources - Error Multiple matching properties for name "datasource.url"

I have a problem connecting to the postgres database using PgPool and ResulSet, then the Statement of sql. Here is my class of service.
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.http.HttpSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.context.annotation.ApplicationScope;
//import io.vertx.reactivex.pgclient.PgPool;
import io.vertx.axle.pgclient.PgPool;
import ml.kalansow.domain.StudentFees;
import ml.kalansow.service.KalansowService;
#Service
#ApplicationScope
public class StudentFeesService implements KalansowService {
private static final Logger LOG = LoggerFactory.getLogger(StudentFeesService.class);
PgPool client;
// ----Constructor------------------------------------------
public StudentFeesService() {
// TODO Auto-generated constructor stub
};
// ------------------------------Method---------------------------------
#Override
public String getServiceName() {
return this.getClass().getName();
}
public void processGetFeesDetails(HttpSession session) {
String strStudentId = (String) session.getAttribute("StudentId");
StudentFees studentFees = new StudentFees();
if (strStudentId != null) {
// This is mandatory before calling the next method
studentFees.setStudentId(strStudentId);
populateFeesInfo(studentFees);
session.setAttribute("studentFees", studentFees);
} else {
LOG.error("Student Id is null");
}
}
private void populateFeesInfo(StudentFees studentFees) {
String strStudentI = studentFees.getStudentId();
io.vertx.sqlclient.impl.Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
StringBuffer sbQuery = new StringBuffer();
sbQuery.append("SELECT * FROM STUDENT_FEES WHERE STUDENT_I=");
sbQuery.append("" + strStudentI + "''");
if (strStudentI != null) {
//connection = DatabaseService.getDBConnection();
connection=(io.vertx.sqlclient.impl.Connection) client.getConnection();
try {
statement = ((Connection) connection).createStatement();
resultSet = statement.executeQuery(sbQuery.toString());
resultSet.next();
studentFees.setJanAcad(resultSet.getString("JAN_ACAD"));
studentFees.setFebAcad(resultSet.getString("FEB_ACAD"));
studentFees.setMarAcad(resultSet.getString("MAR_ACAD"));
studentFees.setAprAcad(resultSet.getString("APR_ACAD"));
studentFees.setMayAcad(resultSet.getString("MAY_ACAD"));
studentFees.setJunAcad(resultSet.getString("JUN_ACAD"));
studentFees.setJulAcad(resultSet.getString("JUL_ACAD"));
studentFees.setAugAcad(resultSet.getString("AUG_ACAD"));
studentFees.setSepAcad(resultSet.getString("SEP_ACAD"));
studentFees.setOctAcad(resultSet.getString("OCT_ACAD"));
studentFees.setNovAcad(resultSet.getString("NOV_ACAD"));
studentFees.setDecAcad(resultSet.getString("DEC_ACAD"));
} catch (SQLException e) {
LOG.error(e.getMessage());
} finally {
/*DatabaseService.closeDBConnection(statement, resultSet);
DatabaseService.realeaseDBConnection();*/
client.close();
}
} else {
LOG.error("Student id is null");
}
}
}
My application properties file contain datasource properties
quarkus.datasource.driver=org.postgresql.Driver
quarkus.reactive-datasource.url=vertx-reactive:postgresql://localhost:5432/test
quarkus.reactive-datasource.username=test
quarkus.reactive-datasource.password=test
And console is here
ERROR [io.qua.dev.DevModeMain] Failed to start Quarkus: java.lang.IllegalArgumentException: Multiple matching properties for name "datasource.url" property was matched by both public java.util.Optional io.quarkus.agroal.runtime.DataSourceRuntimeConfig.url and public java.util.Optional io.quarkus.reactive.pg.client.runtime.DataSourceConfig.url. This is likely because you have an incompatible combination of extensions that both define the same properties (e.g. including both reactive and blocking database extensions)
at io.quarkus.deployment.configuration.matching.PatternMapBuilder.addMember(PatternMapBuilder.java:71)
at io.quarkus.deployment.configuration.matching.PatternMapBuilder.addGroup(PatternMapBuilder.java:60)
at io.quarkus.deployment.configuration.matching.PatternMapBuilder.addMember(PatternMapBuilder.java:85)
at io.quarkus.deployment.configuration.matching.PatternMapBuilder.addGroup(PatternMapBuilder.java:60)
at io.quarkus.deployment.configuration.matching.PatternMapBuilder.makePatterns(PatternMapBuilder.java:35)
at io.quarkus.deployment.configuration.BuildTimeConfigurationReader.(BuildTimeConfigurationReader.java:107)
at io.quarkus.deployment.ExtensionLoader.loadStepsFrom(ExtensionLoader.java:174)
at io.quarkus.deployment.QuarkusAugmentor.run(QuarkusAugmentor.java:85)
at io.quarkus.runner.RuntimeRunner.run(RuntimeRunner.java:114)
at io.quarkus.dev.DevModeMain.doStart(DevModeMain.java:178)
at io.quarkus.dev.DevModeMain.start(DevModeMain.java:96)
You cannot use both the Agroal extension and the Reactive datasources together for the time being.
We are discussing possible ways to fix that here: https://groups.google.com/d/msg/quarkus-dev/3r0lquVsUsc/DVxX7SvQAQAJ .
But for now, your only choice is to use either one or the other.

Getting Session has been Expired for wicket 6.6 in IE and FireFox, working fine in Chrome

1) Upgraded our code from wicket 1.4.9 to wicket 6.6 and from jdk 1.6 to Jdk 1.8
2)First time i am able to log in application, if i click logout and click login
link from homepage getting session expired,
Is there any modification is required in wicket 6.6 to work fine in IE and FireFox, old code(wicket 1.4.9) was working fine in all 3 browsers.
3)We are using Jboss-eap-7.0 server
This the servlet class responsible for JSESSIONID
package com.bnaf.servlet;
import static com.bnaf.CLAS.clasConfiguration;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.grlea.log.SimpleLogger;
import org.owasp.esapi.ESAPI;
import com.bnaf.utils.Constants;
import com.bnaf.utils.RedirectUrlBuilder;
public class ReqAuthnServlet extends HttpServlet {
private static final SimpleLogger log = new SimpleLogger(ReqAuthnServlet.class);
private HttpServletResponse response = null;
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log.info("*********************************************************");
log.info(" Authentication request process initiated ");
log.info("**********************************************************");
this.response = response;
// Valid request parameters
ESAPI.httpUtilities().setCurrentHTTP(request, response);
String sessionIdReq = ServletHelper.getSafeValue(request, "sessionid");
log.debug("Authentication request received. sessionIdReq: [" + sessionIdReq + "]");
if (sessionIdReq == null || sessionIdReq.equals("")) {
log.error("Failed to find requested session ID!");
String message = Constants.ERROR_CODE_ILLEGAL_ARGS + ";" + Constants.ERROR_MSG_ILLEGAL_ARGS;
handleResponse(HttpServletResponse.SC_BAD_REQUEST, message);
return;
}
sessionIdReq = sessionIdReq.trim();
if (request.getSession(false) != null) {
request.getSession(false).invalidate(); // invalidate old session
}
Cookie cookie = new Cookie("JSESSIONID", sessionIdReq);
cookie.setMaxAge(-1);
response.addCookie(cookie);
String authnURL = constructRedirectUrl(request, clasConfiguration().getAuthnURL()) + ";jsessionid=" + sessionIdReq;
log.debug("authnURL = " + authnURL);
response.sendRedirect(response.encodeRedirectURL(authnURL));
log.info(" ****** Generated authentication URL ****** " + authnURL);
log.info(" ****** Authentication request process completed ****** ");
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
private String constructRedirectUrl(HttpServletRequest request, String path) {
// construct redirect url base
RedirectUrlBuilder urlBuilder = new RedirectUrlBuilder();
urlBuilder.setScheme(request.getScheme());
urlBuilder.setServerName(request.getServerName());
urlBuilder.setPort(request.getServerPort());
urlBuilder.setContextPath(request.getContextPath());
urlBuilder.setServletPath(path);
return urlBuilder.getUrl();
}
private void handleResponse(int status, String msg) throws IOException {
if (status != HttpServletResponse.SC_OK) {
response.sendError(status, msg);
} else {
this.response.setStatus(status);
PrintWriter out = this.response.getWriter();
out.println(msg);
out.flush();
out.close();
}
}
}
Below code is in wicket6.6 -- you can find log out method, where session is invalidated.
import static com.bnaf.CLAS.clasConfiguration;
import java.util.List;
import java.util.Locale;
import org.apache.commons.lang.WordUtils;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.core.request.handler.PageProvider;
import org.apache.wicket.core.request.handler.RenderPageRequestHandler;
import org.apache.wicket.markup.head.CssHeaderItem;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.link.PopupSettings;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.http.WebResponse;//new
import org.apache.wicket.request.http.handler.RedirectRequestHandler;//news
import org.apache.wicket.request.mapper.parameter.PageParameters;//new
import org.apache.wicket.request.resource.CssPackageResource;//new
import org.bouncycastle.ocsp.RespData;
import org.grlea.log.SimpleLogger;
import com.bnaf.exception.AuthenticationServiceException;
import com.bnaf.model.ClasDB;
import com.bnaf.utils.Constants;
import com.bnaf.web.ClasApplication;
import com.bnaf.web.UserSession;
import com.bnaf.web.common.panel.ClasBaseAfterLoginPanel;
import com.bnaf.web.onlineregistration.ui.BnafContactAddress;
import com.bnaf.web.onlineregistration.ui.BnafPrivacyPolicy;
import com.bnaf.web.onlineregistration.ui.BnafServCenter;
public class ClasBaseAfterLogin extends WebPage {
ClasDB user;
String userId;
protected String accountType = "";
private static final SimpleLogger LOG = new SimpleLogger(ClasBaseAfterLogin.class);
public ClasBaseAfterLogin(PageParameters parameters) {
String ticket = parameters.get("ticket").toString();
String clasSessionId = parameters.get("clasSessionId").toString();
Authentication au = new Authentication();
List lst;
try {
lst = au.retrieveAuthnStatus(ticket, clasSessionId);
} catch (AuthenticationServiceException e) {
String locale = getSession().getLocale().toString();
String redirectUrl = clasConfiguration().getUserMgmtHomeUrl() + "?loc=" + locale;
getRequestCycle().scheduleRequestHandlerAfterCurrent(new RedirectRequestHandler(redirectUrl));//new
return;
}
String authStat = (String) lst.get(1);
boolean authStatus = Boolean.valueOf(authStat);
userId = (String) lst.get(0);
}
public ClasBaseAfterLogin() {
PopupSettings popupSettings = new PopupSettings().setHeight(825).setWidth(1000);
add(new BookmarkablePageLink("privacyPolicy", BnafPrivacyPolicy.class).setPopupSettings(new PopupSettings(PopupSettings.RESIZABLE
| PopupSettings.SCROLLBARS).setHeight(1500).setWidth(1000)));
add(new BookmarkablePageLink("contactUs", BnafContactAddress.class).setPopupSettings(new PopupSettings(PopupSettings.RESIZABLE
add(new BookmarkablePageLink("servCenter", BnafServCenter.class).setPopupSettings(new PopupSettings(PopupSettings.RESIZABLE
| PopupSettings.SCROLLBARS).setHeight(1500).setWidth(1000)));
Label label = new Label("pageTitle", getLocalizer().getString("label.title", this));
add(label);
userId = (String) UserSession.get().getMyObject();
if (userId == null) {
setResponsePage(Welcome.class);
} else {
try {
user = ClasApplication.get().getPasswordManagerService().getUserProfileDetails(userId);
} catch (AuthenticationServiceException e) {
LOG.errorException(e);
setResponsePage(new BnafCommonErrorPage(this.getPage(), getLocalizer().getString("label.applicaiton.error.page", this),
getLocalizer().getString("request.process.page.error", this)));
}
}
String nameOfUser = null;
if (user != null && user.getLangPref().equals(Constants.USER_LANG_PREF_ENG)) {
nameOfUser = WordUtils.capitalize(user.getName().concat(" ")
.concat((user.getSixthName() != null || (!user.getSixthName().equals("")) ? user.getSixthName() : "")));
} else if (user != null && user.getLangPref().equals(Constants.USER_LANG_PREF_AR)) {
nameOfUser = user.getNameArb().concat(" ")
.concat((user.getSixthNameArb() != null || (!user.getSixthNameArb().equals("")) ? user.getSixthNameArb() : ""));
}
add(new Label("userName", nameOfUser));
add(new ClasBaseAfterLoginPanel("clasbasepanel", userId));
// addCssToPage();
String accountType ="";
String registrationType =(String) UserSession.get().getRegistrationType();
if(!(registrationType.equals(""))){
if(registrationType.equals(Constants.LABEL_BASIC_EKEY_USER)){
accountType = getLocalizer().getString("standard.ekey.account", this);
}else if(registrationType.equals(Constants.LABEL_ADVANCE_EKEY_USER)){
accountType = getLocalizer().getString("advanced.ekey.account", this);
}
}
LOG.info("account_type:" + accountType);
add(new Label("accountType", accountType));
if (getSession().getId() == null) {
//getRequestCycle().setRedirect(true);
throw new RestartResponseException(new BnafCommonErrorPage(this.getPage(), getLocalizer().getString(
"label.session.expired.heading", this), getLocalizer().getString("label.session.expired.error", this)));
}
add(new Link("logout") {
public void onClick() {
String locale = getSession().getLocale().toString();
String redirectUrl = clasConfiguration().getUserMgmtHomeUrl() + "?loc=" + locale;
getSession().invalidateNow();
// getRequestCycle().setRedirect(true);
//getRequestCycle().setRequestTarget(new RedirectRequestTarget(redirectUrl));//old
getRequestCycle().scheduleRequestHandlerAfterCurrent(new RedirectRequestHandler(redirectUrl));//new
}
});
}
/**************NEW WAY TO ADD css FILE FROM WICKET 6.X ************************/
#Override
public void renderHead(IHeaderResponse response) {
response.render(CssHeaderItem.forUrl("css/$/styles.css".replace("$", getSession().getLocale().toString().toLowerCase())));
response.render(CssHeaderItem.forUrl("css/$/reset.css".replace("$", getSession().getLocale().toString().toLowerCase())));
}
/**************END NEW WAY TO ADD css FILE FROM WICKET 6.X ************************/
#Override
protected void configureResponse(WebResponse responses) {
super.configureResponse(responses);
//WebResponse response = (WebResponse) getRequestCycle().getResponse();// getResponse() use Get the active response at the request cycle.
responses.setHeader("Cache-Control", "no-cache, max-age=0,must-revalidate, no-store");
responses.setHeader("Expires", "-1");
responses.setHeader("Pragma", "no-cache");
// responses.setCharacterEncoding("text/html; charset=utf-8");
getSession().setLocale(new Locale(getSession().getLocale().toString()));
}
}

OConcurrentModificationException while adding edges

We're developing a system that we're basing on OrientDB graphs (OrientDB 2.1.3). In the application, we have a thin pojo->graph persistence layer that should do the work properly, but I get OConcurrentModificationException when having multiple threads updating the database.
Here's an example scenario:
Create a Product vertex with edge to Color "Blue"
Simultaneously (while the transaction for creating Product 1 is open) create another Product vertex is created and also adds an edge to Color "Blue".
OConcurrentModificationException is thrown since the version of Color "Blue" vertex is updated. Note that I'm not trying to save or modify the Color "Blue" vertex itself.
As I understood the docs at http://orientdb.com/docs/2.1/Concurrency.html#concurrency-on-adding-edges setting -DridBag.embeddedToSbtreeBonsaiThreshold=-1 should help me avoid my problem, although it still doesn't work.
What am I missing? Is there anything else I can do to avoid this?
Update:
Stacktrace of the exception:
Error on releasing database 'infogileorientdatabasetest' in pool
com.orientechnologies.orient.core.exception.OConcurrentModificationException: Cannot UPDATE the record #40:1 because the version is not the latest. Probably you are updating an old record or it has been modified by another user (db=v34 your=v33)
at com.orientechnologies.orient.core.conflict.OVersionRecordConflictStrategy.checkVersions(OVersionRecordConflictStrategy.java:55)
at com.orientechnologies.orient.core.conflict.OVersionRecordConflictStrategy.onUpdate(OVersionRecordConflictStrategy.java:42)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.checkAndIncrementVersion(OAbstractPaginatedStorage.java:2279)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.doUpdateRecord(OAbstractPaginatedStorage.java:1911)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.commitEntry(OAbstractPaginatedStorage.java:2364)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.commit(OAbstractPaginatedStorage.java:1111)
at com.orientechnologies.orient.core.tx.OTransactionOptimistic.doCommit(OTransactionOptimistic.java:609)
at com.orientechnologies.orient.core.tx.OTransactionOptimistic.commit(OTransactionOptimistic.java:156)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.commit(ODatabaseDocumentTx.java:2582)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.commit(ODatabaseDocumentTx.java:2551)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.commit(ONetworkProtocolBinary.java:1221)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.executeRequest(ONetworkProtocolBinary.java:400)
at com.orientechnologies.orient.server.network.protocol.binary.OBinaryNetworkProtocolAbstract.execute(OBinaryNetworkProtocolAbstract.java:223)
at com.orientechnologies.common.thread.OSoftThread.run(OSoftThread.java:77)
Update 2 - test case
I have reproduced the error using this test case. I would be delighted if there's something else I've done wrong to cause the problem... :-)
Update 3 Updated test case with OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(-1) in a static block.
package se.infogile.persistence.orientdb;
import com.orientechnologies.orient.client.remote.OServerAdmin;
import com.orientechnologies.orient.core.config.OGlobalConfiguration;
import com.orientechnologies.orient.core.db.OPartitionedDatabasePool;
import com.orientechnologies.orient.core.db.OPartitionedDatabasePoolFactory;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.exception.OConcurrentModificationException;
import com.orientechnologies.orient.core.exception.OConfigurationException;
import com.orientechnologies.orient.core.exception.OStorageException;
import com.orientechnologies.orient.core.tx.OTransaction;
import com.orientechnologies.orient.enterprise.channel.binary.OResponseProcessingException;
import com.orientechnologies.orient.server.OServer;
import com.orientechnologies.orient.server.OServerMain;
import com.orientechnologies.orient.server.config.OServerConfiguration;
import com.orientechnologies.orient.server.config.OServerConfigurationLoaderXml;
import com.orientechnologies.orient.server.config.OServerNetworkListenerConfiguration;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;
/**
* Created by heintz on 14/10/15.
*/
public class OrientDBEdgeProblemTest {
static {
OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(-1);
}
private static OPartitionedDatabasePoolFactory dbPoolFactory = new OPartitionedDatabasePoolFactory(100);
private static Logger logger = LoggerFactory.getLogger(OrientDBEdgeProblemTest.class);
private OServer server = null;
private static ExecutorService executorService = Executors.newFixedThreadPool(10);
private static final String dbName = "edgeproblemtest";
#Test
public void testVersionIncrementError() throws Throwable {
OrientGraph graph = getGraph(dbName);
graph.getRawGraph().setDefaultTransactionMode();
graph.createVertexType("Product");
graph.createVertexType("Color");
graph.createEdgeType("HasColor");
graph.getRawGraph().begin(OTransaction.TXTYPE.OPTIMISTIC);
// graph.begin();
Vertex v1 = graph.addVertex("Color", "name", "Blue");
graph.commit();
graph.shutdown();
char[] alphabet = new char[] {'A','B','C','D','E','F','G'};
List<Future> futures = new ArrayList<>();
for (int i = 0; i < 2; i++) {
int pos = i;
futures.add(executorService.submit(new Callable<Object>() {
#Override
public Object call() throws Exception {
OrientGraph g = getGraph(dbName);
try {
g.begin();
Vertex v2 = g.addVertex("Product", "name", "Product "+alphabet[pos]);
g.addEdge(null, v2, v1, "HasColor");
Thread.sleep(200);
g.commit();
} catch (OConcurrentModificationException ocme) {
logger.error("Exception while saving: ", ocme);
Assert.fail("OConcurrentModificationException");
} finally {
g.shutdown();
}
return null;
}
}));
}
for (Future f : futures) {
f.get();
}
executorService.shutdown();
executorService.awaitTermination(5, TimeUnit.SECONDS);
}
#AfterSuite
public void tearDown() throws Exception {
logger.info("Shutting down OrientDB");
if (server != null) {
server.shutdown();
}
}
private OrientGraph getGraph(String dbName) {
String _db = "remote:localhost:3424";
String url = _db + "/" + dbName;
ODatabaseDocumentTx db = null;
try {
OPartitionedDatabasePool pool = dbPoolFactory.get(url,
"root",
"admin");
db = pool.acquire();
} catch (OResponseProcessingException | OConfigurationException | OStorageException oce) {
try {
logger.info("creating new database named " + dbName);
System.err.println("Before DB creation");
OServerAdmin serverAdmin = new OServerAdmin(_db).connect(
"root",
"admin"
);
serverAdmin.createDatabase(dbName, "document", "plocal");
serverAdmin.close();
System.err.println("After DB creation");
} catch (IOException ex) {
logger.error("Unable to create database " + dbName, ex);
}
OPartitionedDatabasePool pool = dbPoolFactory.get(url,
"root",
"admin");
db = pool.acquire();
}
return new OrientGraph(db);
}
#BeforeSuite
public void setUpDatabase() throws Exception {
File f = new File(".");
InputStream is = GraphPersistenceServiceTest.class.getResourceAsStream("/orientdb.config");
Assert.assertNotNull(is);
logger.info("Starting OrientDB");
server = OServerMain.create();
OServerConfigurationLoaderXml loaderXml = new OServerConfigurationLoaderXml(OServerConfiguration.class, GraphPersistenceServiceTest.class.getResourceAsStream("/orientdb.config"));
OServerConfiguration oServerConfiguration = new OServerConfiguration(loaderXml);
System.setProperty("ORIENTDB_ROOT_PASSWORD", "admin");
System.setProperty("RUNMODE", "UNITTEST");
OServerNetworkListenerConfiguration networkConfig = oServerConfiguration.network.listeners.iterator().next();
networkConfig.portRange = "3424-3430";
server.setServerRootDirectory("./target/orientdb");
server.startup(oServerConfiguration);
File serverDir = new File("./target/orientdb");
if (serverDir.exists()) {
FileUtils.deleteDirectory(serverDir);
}
serverDir.mkdirs();
File dbDir = new File(serverDir, "databases");
dbDir.mkdirs();
server.activate();
OGlobalConfiguration.dumpConfiguration(System.out);
Thread.sleep(2000);
}
}
Hi that is because when you add edges to the vertex, vertex itself is modified to store this information, but you may work in mode when information about edges is stored in separate object. Merely use property
-DridBag.embeddedToSbtreeBonsaiThreshold=true and you will rid off this exception.

How do I sort/filter Google Code projects by stars?

I would like to know what projects hosted on Google Code that have the most stars, especially when searching by label, like this:
https://code.google.com/hosting/search?q=label%3aAndroid
Sort by stars is not supported on the project search page. Was able to write some page scrapping code to get the required information.
Hope it helps.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class ReadGoogleProjectSortByStars {
public static void main(String[] args) throws IOException {
String urlPath = "https://code.google.com/hosting/search?q=label%3AAndroid&filter=0&mode=&start=";
// urlPath = "https://code.google.com/hosting/search?q=label%3AAndroid+stackoverflow&projectsearch=Search+projects&filter=0&mode=&start=";
int start = 0;
List<Project> projects = new ArrayList<Project>();
boolean done = false;
while(!done) {
String urlStr = urlPath + start;
URL url = new URL(urlStr);
BufferedReader in = new BufferedReader(
new InputStreamReader(url.openStream()));
String inputLine;
String projectUrl = null, stars = null;
while ((inputLine = in.readLine()) != null) {
int urlIndex = -1, starIndex = -1;
if(inputLine.contains(" style=\"font-size:medium\">") && (urlIndex = inputLine.indexOf(" href=\"/p/")) != -1) {
if(projectUrl != null) {
Project project = new Project();
project.url = projectUrl;
project.stars = "0";
projects.add(project);
}
String projectTempUrl = inputLine.substring(urlIndex + " href=\"/p/".length());
projectUrl = "https://code.google.com/p/" + projectTempUrl.substring(0, projectTempUrl.indexOf("\""));
}
if((starIndex = inputLine.indexOf("id=\"star_count-")) != -1) {
stars = inputLine.substring(inputLine.indexOf(">") + 1, inputLine.indexOf("</span>"));
Project project = new Project();
project.url = projectUrl;
project.stars = stars;
projects.add(project);
projectUrl = stars = null;
}
if(inputLine.contains(" - did not generate any results.")) {
done = true;
break;
}
}
in.close();
start +=10;
if(projectUrl != null) {
Project project = new Project();
project.url = projectUrl;
project.stars = "0";
projects.add(project);
}
}
Collections.sort(projects, new Comparator<Project>() {
#Override
public int compare(Project project1, Project project2) {
Integer stars1 = Integer.parseInt(project1.stars);
Integer stars2 = Integer.parseInt(project2.stars);
return -stars1.compareTo(stars2);
}
});
System.out.println("Total projects:" +projects.size());
for (Project project : projects) {
System.out.println(project.url + ":" + project.stars);
}
}
}
class Project {
String url;
String stars;
}
I would have say use &sort=stars as they do in the support of google code but it doesn't work well. I'm not sure it's possible unfortunately...

cakephp user authentication for adobe air app

I have a web application developed using flex and cakephp. My client need to make a desktop application of that web application using Adobe Air. The conversion of the flex to Air is done successfully. I the flex application the communication of flex and cakephp is handled using a remotes controller.
In air application I have a problem of authenticating the user with cakephp default user authentication. Can anyone help me to find a solution for this?
i suggest you to send your user credentials via POST to your cakephp backend.
A login function in your UsersController would look something like this:
public function login() {
if ($this->Auth->login()) {
$this->serviceResponse(Status::SUCCESS);
} else {
$this->serviceResponse(Status::AUTH_FAILED);
}
}
// this is just an example out of my appcontroller to send json responses
public function serviceResponse($code, $data = array()) {
$response = compact('code', 'data');
$this->response->body(json_encode($response));
$this->response->send();
$this->shutdownProcess();
exit;
}
// I also defined a class for return statuses
class Status {
const SUCCESS = 'success';
const ERROR = 'error';
...
}
Basically, you want to send the validation request as an ajax request. To do that you need to modify headers, capture session ids through cookies and post them to keep the session alive. It expects a JSON object returned from Cake.
I've created a couple Flex classes that achieve just this for a Flex Mobile App and a CakePHP backend. It should work the same for your needs.
It's in two files, the AutoValidationUrlRequest.as extends the HeaderURLRequest.as file. I'm not positive but there may be a couple variables to change, but overall it works very well and probably won't take more than a couple changes to get it working on your app.
To use it, simply create a new AutoValidationUrlRequest object and add an event listener on the headerUrlRequestComplete Event and then run AutoValidationUrlRequest.send(...) to POST. there is also a handy method called convertToPostVars for easy Cake Friendly Post variables.
AutoValidationUrlRequest.as:
package libs
{
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.HTTPStatusEvent;
import models.LocalDeviceData;
import models.Model;
import mx.collections.ArrayCollection;
import mx.core.FlexGlobals;
import mx.utils.ObjectUtil;
[Event("LoginFailed")]
[Event("MobileUserDoesNotExist")]
public class AutoValidationURLRequest extends HeaderURLRequest
{
public static const LOGIN_FAILED:String = "LoginFailed";
public static const MOBILE_USER_DOES_NOT_EXIST:String = "MobileUserDoesNotExist";
/**
* will automatically be set by this class, if not set will login
*/
public var requestHeaders:Object = new Object();
private var _cookie:Object;
/**
* should be an object with name of the cookie variables parsed in as key/value pairs
*/
protected function set cookie(ck:Object):void{
_cookie = ck;
}
protected function get cookie():Object{
return _cookie;
}
public function AutoValidationURLRequest(){
};
public function send(url:String, postData:Object, generateUrlVars:Boolean = true):void{
if(generateUrlVars){
postData = convertToPostVars(postData);
}
sendRequest("http://yourwebsite.com"+url, postData, requestHeaders);
}
override protected function parseHeaders(e:HTTPStatusEvent):void{
super.parseHeaders(e);
if('Set-Cookie' in headers){
requestHeaders['Cookie'] = parseCookie(headers['Set-Cookie']);
//requestHeaders['User-Agent'] = headers['User-Agent'];
}
}
/**
* returns the cookie key/val string for send requests back to the server
*/
protected function parseCookie(cookieString:String):String{
var cookieObj:Object = new Object();
var cookieBits:Array = cookieString.split("; ");
return cookieBits[0];
/*
for each(var ck:String in cookieBits){
var cb:Array = ck.split("=");
cookieObj[cb[0]] = cb[1];
}
return cookieObj;
*/
}
}
}
HeaderURLRequest.as:
package libs
{
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.HTTPStatusEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestHeader;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
import mx.core.FlexGlobals;
import mx.rpc.events.ResultEvent;
import mx.utils.ObjectUtil;
[Event("headerUrlRequestComplete")]
public class HeaderURLRequest extends EventDispatcher
{
public static const HEADERURLREQUEST_COMPLETE:String = "headerUrlRequestComplete";
public var headers:Array = [];
public var data:Object = new Object();
public var variables:Object = new Object();
public var invalidFields:Object = new Object();
public var errorMsg:String = "";
/**
* the headers array must contain an object with a 'name' key and a 'value' key eg: cookie: <cookieStr>
*/
public function HeaderURLRequest():void{
}
public function sendRequest(url:String, postData:Object = null, requestHeaders:Object = null):void{
var urlLoader:URLLoader = new URLLoader()
var urlRequest : URLRequest = new URLRequest(url);
//make it an ajax request
urlRequest.requestHeaders.push(new URLRequestHeader('X-Requested-With', 'XMLHttpRequest'));
for(var header:* in requestHeaders){
var authHeader:URLRequestHeader = new URLRequestHeader(header as String, requestHeaders[header]);
urlRequest.requestHeaders.push(authHeader)
}
var urlVariables:URLVariables = new URLVariables();
for (var vars:* in postData){
urlVariables[vars] = postData[vars];
}
urlRequest.method = URLRequestMethod.POST
urlRequest.data = urlVariables;
urlLoader.addEventListener(Event.COMPLETE, getData);
urlLoader.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, parseHeaders);
urlLoader.load(urlRequest);
}
public function convertToPostVars(postData:Object, prependKeyName:String = ""):Object{
var params:Object = {};
if(prependKeyName == ""){
params['_method'] = 'POST';
}
for (var item:* in postData){
var objtype:Object = ObjectUtil.getClassInfo(postData[item]);
if(objtype.name == "Object"){
var modelKeyName:String = prependKeyName+"["+item+"]";
var subParams:Object = convertToPostVars(postData[item],modelKeyName);
params = merge(params, subParams);
}else{
params["data"+prependKeyName+"["+item+"]"] = postData[item];
}
}
return params;
}
public function flashErrorMsg():String{
var err:String = errorMsg;
errorMsg = "";
return err;
}
protected function parseHeaders(e:HTTPStatusEvent):void{
var i:Number=0;
headers = [];
for each(var header:URLRequestHeader in e.responseHeaders){
headers[header.name] = header.value;
i++;
}
}
protected function getData(e:Event):void{
//trace('data: ');
if(e.currentTarget.data == ''){
e.currentTarget.data = '{}';
}
data = JSON.parse(e.currentTarget.data);
//trace(ObjectUtil.toString(data));
if(data.hasOwnProperty('variables')){
variables = data.variables;
if (variables != null){
if(variables.hasOwnProperty('invalidFields')){
invalidFields = variables.invalidFields;
for (var error:String in invalidFields){
errorMsg += invalidFields[error] + "\n\n";
}
}
}else{
//no variable data found!!
}
}
dispatchEvent(new Event(HEADERURLREQUEST_COMPLETE));
}
public function isEmpty(obj:Object){
var isEmpty:Boolean = true;
for (var n in obj) { isEmpty = false; break; }
return isEmpty;
}
public function merge( obj0:Object, obj1:Object ):Object
{
var obj:Object = { };
for( var p:String in obj0 )
{
obj[ p ] = ( obj1[ p ] != null ) ? obj1[ p ] : obj0[ p ];
//trace( p, ' : obj0', obj0[ p ], 'obj1', obj1[ p ], '-> new value = ', obj[ p ] );
}
for (var p1:String in obj1){
if(!obj.hasOwnProperty(p1)){
obj[ p1 ] = obj1[ p1 ] ;
}
}
return obj;
}
}
}
Also, using this with my forked version of Jose Gonzalez's CakePHP ajax_controller plugin is really handy. It basically takes any Ajax Request and converts all view variables and outputs them into a JSON object, no rendered view. Otherwise, if you're not using an ajax request, Cake will render the views normally. Good Luck!

Resources