Commit 50eaff10 by Nilu

J007 adding short url to share. creating short url for existing jobs via a batch

parent 10d141aa
......@@ -26,6 +26,7 @@
<column name="level_id" type="Long" length="11" nullable="false"/>
<column name="client_id" type="Long" length="11" nullable="true"/>
<column name="company_user_id" type="Long" length="11" nullable="true"/>
<column name="shortened_url_id" type="Long" length="11" nullable="true"/>
</NODE>
<NODE name="INDEX" factory="Participant" class="oneit.sql.transfer.DefineIndexOperation" tableName="tl_job" indexName="idx_tl_job_client_id" isUnique="false"><column name="client_id"/></NODE>
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- @AutoRun -->
<OBJECTS name="" xmlns:oneit="http://www.1iT.com.au"><NODE name="Script" factory="Vector">
<NODE name="DDL" factory="Participant" class="oneit.sql.transfer.DefineTableOperation">
<tableName factory="String">tl_shortened_url</tableName>
<column name="object_id" type="Long" nullable="false" length="11"/>
<column name="object_last_updated_date" type="Date" nullable="false" length="22"/>
<column name="object_created_date" type="Date" nullable="false" length="22"/>
<column name="code" type="String" nullable="false" length="8"/>
<column name="url_link" type="CLOB" nullable="false"/>
</NODE>
</NODE></OBJECTS>
\ No newline at end of file
......@@ -25,7 +25,8 @@ CREATE TABLE tl_job (
country varchar(200) NULL,
level_id numeric(12) NOT NULL,
client_id numeric(12) NULL,
company_user_id numeric(12) NULL
company_user_id numeric(12) NULL,
shortened_url_id numeric(12) NULL
);
......
-- DROP TABLE tl_shortened_url;
CREATE TABLE tl_shortened_url (
object_id int NOT NULL ,
object_last_updated_date datetime DEFAULT getdate() NOT NULL ,
object_created_date datetime DEFAULT getdate() NOT NULL
,
code varchar(8) NOT NULL,
url_link text NOT NULL
);
ALTER TABLE tl_shortened_url ADD
CONSTRAINT PK_tl_shortened_url PRIMARY KEY
(
object_id
) ;
\ No newline at end of file
......@@ -26,7 +26,8 @@ CREATE TABLE tl_job (
country varchar2(200) NULL,
level_id number(12) NOT NULL,
client_id number(12) NULL,
company_user_id number(12) NULL
company_user_id number(12) NULL,
shortened_url_id number(12) NULL
);
......
-- DROP TABLE tl_shortened_url;
CREATE TABLE tl_shortened_url (
object_id number(12) NOT NULL ,
object_last_updated_date date DEFAULT SYSDATE NOT NULL ,
object_created_date date DEFAULT SYSDATE NOT NULL
,
code varchar2(8) NOT NULL,
url_link clob NOT NULL
);
ALTER TABLE tl_shortened_url ADD
CONSTRAINT PK_tl_shortened_url PRIMARY KEY
(
object_id
) ;
\ No newline at end of file
......@@ -26,7 +26,8 @@ CREATE TABLE tl_job (
country varchar(200) NULL,
level_id numeric(12) NOT NULL,
client_id numeric(12) NULL,
company_user_id numeric(12) NULL
company_user_id numeric(12) NULL,
shortened_url_id numeric(12) NULL
);
......
-- @AutoRun
-- drop table tl_shortened_url;
CREATE TABLE tl_shortened_url (
object_id numeric(12) NOT NULL ,
object_last_updated_date timestamp DEFAULT NOW() NOT NULL ,
object_created_date timestamp DEFAULT NOW() NOT NULL
,
code varchar(8) NOT NULL,
url_link text NOT NULL
);
ALTER TABLE tl_shortened_url ADD
CONSTRAINT pk_tl_shortened_url PRIMARY KEY
(
object_id
) ;
\ No newline at end of file
package performa.batch;
import oneit.appservices.batch.ORMBatch;
import oneit.logging.LogLevel;
import oneit.logging.LogMgr;
import oneit.logging.LoggingArea;
import oneit.objstore.ObjectTransaction;
import oneit.objstore.StorageException;
import oneit.objstore.rdbms.filters.IsNullFilter;
import oneit.utils.parsers.FieldException;
import performa.orm.Job;
public class URLShortnerBatch extends ORMBatch
{
public static LoggingArea URL_SHORTNER_BATCH = LoggingArea.createLoggingArea("URLShortnerBatch");
@Override
public void run(ObjectTransaction ot) throws StorageException, FieldException
{
LogMgr.log (URL_SHORTNER_BATCH, LogLevel.DEBUG2, "RUNNING URL Shortner Batch");
Job[] jobs = Job.SearchByAll()
.andShortenedURL(new IsNullFilter<>())
.search(ot);
for (Job job : jobs)
{
job.createShortenedURL();
LogMgr.log(URL_SHORTNER_BATCH, LogLevel.DEBUG2, "Setting Shortned URL to job : ", job);
}
}
}
\ No newline at end of file
......@@ -14,6 +14,7 @@ import oneit.servlets.process.SaveFP;
import oneit.utils.BusinessException;
import oneit.utils.DateDiff;
import performa.orm.Job;
import performa.orm.ShortenedURL;
import performa.orm.types.JobStatus;
......@@ -29,12 +30,17 @@ public class SaveJobFP extends SaveFP
Job oldJob = (Job) job.getEarliestBackup();
if(oldJob != null && oldJob.getJobStatus() == JobStatus.DRAFT)
if(oldJob != null && oldJob.getJobStatus() == JobStatus.DRAFT && job.getJobStatus() == JobStatus.OPEN)
{
job.setJobStatus(JobStatus.OPEN);
job.setApplyBy(DateDiff.add(DateDiff.getToday(), Calendar.DATE, 30));
job.setOpenDate(new Date());
}
if(job.getJobStatus() == JobStatus.OPEN && job.getShortenedURL() == null)
{
job.createShortenedURL();
}
return super.processForm(process, submission, params);
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package performa.orm;
import java.util.*;
import oneit.logging.LoggingArea;
import oneit.net.LoopbackHTTP;
import oneit.objstore.*;
import oneit.objstore.cloning.AssocCopyingRule;
import oneit.objstore.cloning.BusinessCopyHelper;
......@@ -499,4 +500,43 @@ public class Job extends BaseJob
return Arrays.asList(new JobStatus[]{JobStatus.OPEN, JobStatus.COMPLETE, JobStatus.FILLED});
}
private String getURL()
{
return LoopbackHTTP.getRemoteAccessURL("/ApplicantPortal-ApplyJob.htm?" + "id=" + getID() + "&key=" + getRandomKey());
}
public void createShortenedURL() throws StorageException, FieldException
{
ShortenedURL shortenedURL = ShortenedURL.createShortenedURL(getTransaction());
shortenedURL.setUrlLink(getURL());
shortenedURL.setCode(generateUniqueCode());
setShortenedURL(shortenedURL);
}
private String generateUniqueCode()
{
String randomString;
while (true)
{
randomString = RandomStringGen.getRandomStringGen().generateAlphaNum(6);
ShortenedURL[] searchByCode = ShortenedURL.searchByCode(getTransaction(), randomString);
if (searchByCode.length == 0)
{
return randomString;
}
}
}
public String getShortenedUrlLink()
{
return LoopbackHTTP.getRemoteAccessURL("/j/" + (getShortenedURL() != null ? getShortenedURL().getCode() : ""));
}
}
\ No newline at end of file
......@@ -50,6 +50,7 @@
<SINGLEREFERENCE name="Level" type="Level" dbcol="level_id" mandatory="true"/>
<SINGLEREFERENCE name="Client" type="Client" dbcol="client_id" backreferenceName="Jobs"/>
<SINGLEREFERENCE name="CompanyUser" type="CompanyUser" dbcol="company_user_id" />
<SINGLEREFERENCE name="ShortenedURL" type="ShortenedURL" dbcol="shortened_url_id" />
</TABLE>
......
package performa.orm;
import oneit.objstore.StorageException;
import oneit.utils.CollectionUtils;
public class ShortenedURL extends BaseShortenedURL
{
private static final long serialVersionUID = 0L;
// This constructor should not be called
public ShortenedURL ()
{
// Do not add any code to this, always put it in initialiseNewObject
}
@Override
public boolean filterByCode(String code) throws StorageException
{
return CollectionUtils.equals(code, getCode());
}
}
\ No newline at end of file
<?xml version="1.0"?>
<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='http://www.oneit.com.au/schemas/5.2/BusinessObject.xsd'>
<BUSINESSCLASS name="ShortenedURL" package="performa.orm">
<TABLE name="tl_shortened_url" tablePrefix="object" polymorphic="FALSE">
<ATTRIB name="Code" type="String" dbcol="code" mandatory="true" length="8"/>
<ATTRIB name="UrlLink" type="String" dbcol="url_link" mandatory="true" />
</TABLE>
<SEARCH type="all" paramFilter="object_id is not null" orderBy="object_created_date desc">
</SEARCH>
<SEARCH type="ByCode" paramFilter="object_id is not NULL" checkTXObjects="TRUE">
<PARAM name="Code" type="String" paramFilter="trim(code) = ${Code}"/>
</SEARCH>
</BUSINESSCLASS>
</ROOT>
\ No newline at end of file
package performa.utils;
import oneit.appservices.config.ConfigMgr;
import oneit.components.InitialisationParticipant;
import oneit.components.ParticipantInitialisationContext;
import oneit.logging.LogLevel;
import oneit.logging.LogMgr;
import oneit.logging.LoggingArea;
import oneit.objstore.ObjectTransaction;
import oneit.objstore.services.TransactionServicesFactory;
import oneit.servlets.utils.BaseHttpServletRequest;
import oneit.servlets.utils.BaseHttpServletResponse;
import oneit.servlets.utils.decorator.ServletDecorator;
import oneit.servlets.utils.decorator.ServletDecoratorConfig;
import oneit.utils.BusinessException;
import oneit.utils.InitialisationException;
import performa.orm.ShortenedURL;
public class ShortenedURLDecorator implements ServletDecorator, InitialisationParticipant
{
public static final LoggingArea LOG = LoggingArea.createLoggingArea("ShortenedURLFilter");
public static final String JOB_URL_PREFIX = "/j/";
@Override
public void processRequest(ServletDecoratorConfig config, BaseHttpServletRequest request, BaseHttpServletResponse response) throws Exception
{
String pathInfo = request.getServletPath();
LogMgr.log(LOG, LogLevel.PROCESSING1, "ShortenedURLFilter.doFilter: ", pathInfo);
if (pathInfo != null && pathInfo.contains(JOB_URL_PREFIX))
{
int lastIndex = pathInfo.lastIndexOf("/");
String shortcut = pathInfo.substring(lastIndex+1);
try
{
TransactionServicesFactory servicesFactory = (TransactionServicesFactory) ConfigMgr.getConfigObject(ConfigMgr.GLOBAL_CONFIG_SYSTEM, "TransactionServices");
ObjectTransaction objTran = new ObjectTransaction (servicesFactory);
ShortenedURL[] shortURL = ShortenedURL.searchByCode(objTran, shortcut);
if(shortURL != null && shortURL.length > 0)
{
request.setAttribute("DecoratorFilter.TERMINATE", "Yes");
response.sendRedirect(shortURL[0].getUrlLink());
}
}
catch (Exception e)
{
LogMgr.log(LOG, LogLevel.BUSINESS2, e, "Problem find the shorted url");
throw new BusinessException("Something went wrong. Please contact Admin");
}
}
config.forwardRequest(request, response);
}
@Override
public void init(ParticipantInitialisationContext context) throws InitialisationException
{
}
}
\ No newline at end of file
......@@ -1467,23 +1467,33 @@ span.rate-label {
margin-right: 8px;
}
.share-link {
width: 30.578%;
width: 40%;
background: url(../images/link-icon.png) no-repeat ;
height: 100px;
text-align: left;
background-position: left 20px center;
padding: 30px 0 20px 60px;
}
.copy-link{
font-size: 11px;
color: #9b9b9b;
}
.share-btn {
width: 13.002%;
width: 12%;
background-color: #efefef;
}
.linkdin-icon {
width: 13.6%;
width: 12%;
}
.facebook-icon {
width: 13.73%;
width: 12%;
}
.shape-icon{
width: 14.73%;
width: 12%;
}
.more-icon {
width: 14.3%;
width: 12%;
}
.goto-job-btn{
display: inline-block;
......
<?xml version="1.0"?>
<OBJECTS name="AdminPortal">
<NODE name="DecoratorFilter::performa">
<DECORATOR factory="Participant" class="performa.utils.ShortenedURLDecorator"/>
</NODE>
<NODE name="dynamic_content_form_client" factory="Participant">
<INHERITS factory="Named" nodename="dynamic_content_form"/>
......
......@@ -128,6 +128,15 @@
</TASK>
<TASK factory="Participant" class="oneit.appservices.batch.DefaultTask" lockName="performa">
<RUN class="performa.batch.URLShortnerBatch" factory="Participant"/>
<WHEN factory="MetaComponent" component="BatchSchedule" selector="performa.runbatch">
<NODE name="schedule" class="oneit.appservices.batch.NeverSchedule">
</NODE>
</WHEN>
</TASK>
</NODE>
......
......@@ -13,8 +13,9 @@
Debug.assertion(job != null, "Job is null in admin portal create job");
String url = LoopbackHTTP.getRemoteAccessURL("/ApplicantPortal-ApplyJob.htm?" + "id=" + job.getID() + "&key=" + job.getRandomKey());
String nextPage = WebUtils.getSamePageInRenderMode(request, WebUtils.VIEW_APPLICANTS);
String url = job.getShortenedUrlLink();
boolean fromJob = request.getParameter("fromJob") != null ? Boolean.parseBoolean(request.getParameter("fromJob")) : false;
String nextPage = WebUtils.getSamePageInRenderMode(request, (fromJob ? "Page" : WebUtils.VIEW_APPLICANTS));
%>
<script>
......@@ -43,7 +44,12 @@
<div class="form-page-area">
<div class="job-share-icon">
<ul>
<li class="share-link" onclick="copyToClipboard()"><a href="#"><img src="images/link-icon.png" /> Copy link to clipboard</a></li>
<li class="share-link" onclick="copyToClipboard()">
<a class="linked-col" href="#">
<div><%= url %></div>
<span class="copy-link">(Copy link to clipboard)</span>
</a>
</li>
<li class="share-btn"><a href="#">Share</a></li>
<li class="linkdin-icon"><a href="#"><img src="images/linkedin-icon.png" /></a></li>
<li class="facebook-icon"><a href="#"><img src="images/facebook-icon.png"/></a></li>
......@@ -55,11 +61,15 @@
This job will be open for 30 days until&nbsp;<oneit:toString value="<%= job.getApplyBy() %>" mode="PerformaDate"/>.
</p>
<div class="text-center">
<oneit:button value="Go to Job" name="gotoPage" cssClass="btn btn-primary largeBtn"
<oneit:button value="<%= "Go to Job" + (fromJob ? "s" : "")%>" name="gotoPage" cssClass="btn btn-primary largeBtn"
requestAttribs='<%= CollectionUtils.mapEntry("nextPage", nextPage).toMap() %>'/>
</div>
<div class="space-55"></div>
</div>
</div>
<style>
.job-share-icon li a.linked-col {line-height: 20px;}
</style>
</oneit:form>
</oneit:dynIncluded>
......@@ -6,11 +6,12 @@
<oneit:dynIncluded>
<%
Job job = (Job) process.getAttribute("Job");
String nextPage = WebUtils.getSamePageInRenderMode(request, WebUtils.CREATED_JOB);
String nextPage = WebUtils.getSamePageInRenderMode(request, WebUtils.CREATED_JOB) + "&fromJob=true";
String firstPage = WebUtils.getSamePageInRenderMode(request, WebUtils.CREATE_JOB);
String secondPage = WebUtils.getSamePageInRenderMode(request, WebUtils.ASSESSMENT_CRITERIA);
String thirdPage = WebUtils.getSamePageInRenderMode(request, WebUtils.WORKPLACE_CULTURE);
String fourthPage = WebUtils.getSamePageInRenderMode(request, WebUtils.JOB_MATCH);
String fifthPage = WebUtils.getSamePageInRenderMode(request, WebUtils.JOB_REVIEW);
Article jobsArticle = WebUtils.getArticleByShortCut(transaction, WebUtils.JOBS);
String jobsPage = jobsArticle.getLink(request, CollectionUtils.mapEntry("cms.rm", WebUtils.VIEW_APPLICANTS).toMap());
......@@ -214,6 +215,7 @@
<oneit:button value="Open this job" name="saveJob" cssClass="btn btn-primary btn-green top-margin-25 largeBtn"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage)
.mapEntry ("fromPage", fifthPage)
.mapEntry ("restartProcess", Boolean.TRUE)
.mapEntry ("attribNamesToRestore", Collections.singleton("Job"))
.toMap() %>" />
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- @AutoRun -->
<OBJECTS name="" xmlns:oneit="http://www.1iT.com.au">
<NODE name="Script" factory="Vector">
<NODE name="DDL" factory="Participant" class="oneit.sql.transfer.RedefineTableOperation">
<tableName factory="String">tl_job</tableName>
<column name="shortened_url_id" type="Long" length="11" nullable="true"/>
</NODE>
</NODE>
</OBJECTS>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!-- @AutoRun -->
<OBJECTS name="" xmlns:oneit="http://www.1iT.com.au">
<NODE name="Script" factory="Vector">
<NODE name="DDL" factory="Participant" class="oneit.sql.transfer.DefineTableOperation">
<tableName factory="String">tl_shortened_url</tableName>
<column name="object_id" type="Long" nullable="false" length="11"/>
<column name="object_last_updated_date" type="Date" nullable="false" length="22"/>
<column name="object_created_date" type="Date" nullable="false" length="22"/>
<column name="code" type="String" nullable="false" length="8"/>
<column name="url_link" type="CLOB" nullable="false"/>
</NODE>
</NODE>
</OBJECTS>
\ No newline at end of file
Run URLShortnerBatch - this will add URL shortner to existing jobs.
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment