dannyman.toldme.com


JIRA, Python, Technical

Jython Validator Cookbook

Link: https://dannyman.toldme.com/2012/09/25/jython-validator-cookbook/

Building on a previous post to validate user time tracking, a few “cookbook” scripts that may be handy to you or me in the future.

JIRA 4.2, YMMV.

Validate User Time Tracking

Somewhat elaborate: enforce that time worked has been logged, except under certain circumstances. See original post.

import com.atlassian.jira.issue.worklog.Worklog
from com.atlassian.jira import ComponentManager
 
# Time Already Logged
timespent = issue.getTimeSpent()
# Time Logged via current screen
try:
    timelogged = dict(issue.getModifiedFields())['worklog']
except:
    timelogged = False
 
# Duplicate Issue?  It is as good as logged!
resolution = issue.getResolution()
if resolution['name'] == "Duplicate":
    timelogged = True
if resolution['name'] == "Self Corrected":
    timelogged = True
 
# Nagios likes to close tickets, but doesn't get paid
user = ComponentManager.getInstance().getJiraAuthenticationContext().getUser()
if user.getName() == "nagios":
    timelogged = True
 
if timespent < = 0 and timelogged == False:
    result = False
    description = "Please log the time you spent on this ticket."

Assign Unassigned Issue to User

This helps make sure tickets get assigned.

# -*- coding: UTF-8 -*-
from com.atlassian.jira import ComponentManager
 
assignee = issue.getAssignee()
user = ComponentManager.getInstance().getJiraAuthenticationContext().getUser()
 
if not issue.getAssignee():
    issue.setAssignee(ComponentManager.getInstance().getJiraAuthenticationContext().getUser())

Validate Custom Field Value

We have a particular custom field which can be set UNKNOWN by the Reporter, but which should be cleaned up by the Assignee.

from com.atlassian.jira import ComponentManager
 
cfm = ComponentManager.getInstance().getCustomFieldManager()
product = issue.getCustomFieldValue(cfm.getCustomFieldObject('customfield_12345'))
 
if product == 'UNKNOWN':
    result = False
    description = "Please set CUSTOM_FIELD value appropriately."

Feedback Welcome


Technical

HOWTO: Style a Multi-Column List in HTML

Link: https://dannyman.toldme.com/2012/10/22/html-css-ul-li-columns/

For a project at work I was asked if I could lay out a long table-of-contents in our CMS as multiple columns. Logically enough, the table-of-contents renders as a flat, unordered list (UL) of list items (LI) … arranging that as multiple columns is a preposterous idea! Of course, preposterous questions can be very interesting.

So, we start with something like this:

		<h1>Yadda Yadda</h1>
 
		<ul class="columns">
			<li>BLAH blah blah one</li>
			<li>BLAH blah blah two</li>
			<li>BLAH blah blah three</li>
			<li>BLAH blah blah four</li>
			<li>BLAH blah blah five</li>
			<li>BLAH blah blah six</li>
			<li>BLAH blah blah seven</li>
			<li>BLAH blah blah eight really long example</li>
			<li>BLAH blah blah nine</li>
			<li>BLAH blah blah ten</li>
			<li>BLAH blah blah eleven</li>
			<li>BLAH blah blah twelve</li>
		</ul>
 
		<h1>Yappa Yappa</h1>

Which renders as:

Yadda Yadda

Yappa Yappa

Okay. So, multiple columns? That is what TABLE is for, but we are dealing with UL. But I have my old friend the float attribute, so I define a style sheet:

			ul.columns li {
				list-style: none;
				float: left;
				width: 30%;
			}
			h1 { clear: left; }

Now we render as three columns:

Yadda Yadda

Yappa Yappa

Two columns? Four? Just tune the width attribute:

			ul.columns li {
				list-style: none;
				float: left;
				width: 45%;
			}
			h1 { clear: left; }

And you get:


It is not perfect. The content renders left-to-right, so strictly speaking, these aren’t columns.

If you narrow enough to cause wrapping you get some odd gaps.

Due to margins and the like, you can’t just say three columns is 33%, two columns is 50% . . . if you narrow this page enough you’ll see a graceful degradation from more columns to fewer.

Here’s a more dynamic example, where wider pages will get more columns:

			ul.columns li {
				list-style: none;
				float: left;
				width: 15em;
			}
			h1 { clear: left; }

Renders as:


The block following your UL will need to clear the floated content, hence the clear: left on the H1, above.

See also:

Feedback Welcome


Religion, Testimonials

Hajj

Link: https://dannyman.toldme.com/2012/10/25/hajj/

“According to Islamic tradition the Kaaba was re-constructed by Abraham. It is stated in the Qur’an that this was the first house that was built for humanity to worship Allah.”

Malcolm X, an American human rights activist, describes the sociological atmosphere he experienced at Hajj as follows:

There were tens of thousands of pilgrims, from all over the world. They were of all colors, from blue-eyed blondes to black-skinned Africans. But we were all participating in the same ritual, displaying a spirit of unity and brotherhood that my experiences in America had led me to believe never could exist between the white and the non-white. America needs to understand Islam, because this is the one religion that erases from its society the race problem.

A 2008 study on the longer-term effect of participating in the Islamic pilgrimage found that Muslims’ communities become more open after the Hajj experience. Entitled “Estimating the Impact of the Hajj: Religion and Tolerance in Islam’s Global Gathering”, a study conducted in conjunction with Harvard University’s John F. Kennedy School of Government found that the Hajj experience promotes peaceful coexistence, equality, and harmony. Specifically, the report states that the Hajj “increases belief in equality and harmony among ethnic groups and Islamic community and that “Hajjis (those who have performed the Hajj) show increased belief in peace, and in equality and harmony among adherents of different religions”

Sourced from Wikipedia: Kaaba, Hajj

I kinda like just listening to the guy praying along in Arabic. Very relaxing. Even when I was a kid, I thought it was a cool idea that when Muslims pray, wherever they are, they face the same spot. Reading observations that having what amounts to a yearly conference that brings people from across the world together in fellowship . . . that is also a good thing.

Organized religion, and especially Islam, are not without some serious problems, so it is reassuring to see some of the spiritual unity and good spirit that result from a practice that so many people today and throughout history have dedicated their lives to.

Feedback Welcome


Letters to The Man, Technology, Testimonials

Advice to Hotels

Link: https://dannyman.toldme.com/2012/10/30/free-internet-duh/

From a survey I just filled out regarding a business trip to London:

Internet access … kept dropping packets, and I had to keep logging in to it via iPass. Don’t gouge customers, just let them on. This is seriously trivial, low-hanging fruit, which can make all the difference in the world esp for an international business traveler avoiding mobile roaming charges.

I would without hesitation stay at a more mediocre hotel that could deliver hassle-free, reliable Internet service, and the hassle-free starts with avoiding the damn tariff screen and just letting your guests on … guests who will appreciate this no-nonsense convenience far more than whether the staff have been properly trained to smile, &c.

I gotta say … we seem to “get this” in America … I’ve stayed at plenty of budget motels which offered complimentary, hassle-free, reliable Internet access. Though, I don’t recall having the same pleasure at a hotel in New York, where you could get free Internet in the lobby, but had to pay for it upstairs in your room.

For many of us, network access is kind of like tap water: we take it for granted that it should just flow, and not require one to jump through hoops to pay an additional $20/day. If there’s a business hotel chain that has figured this out, let me know, because my loyalty would be easily won.

Feedback Welcome


JIRA, Technical

JIRA Workflow Transition Condition: check_parent_resolved.py

Link: https://dannyman.toldme.com/2012/11/07/jython-workflow-transition-check-parent/

It took a few hours to figure this hook out, so I’m including my hard-won lines of code here.

# -*- coding: UTF-8 -*-
# Check if PARENT is resolved.
# Monitoring creates Events in the Event queue, these Events
# automatically create Incident children.
# We don't want to resolve any Incident children until the parent Event
# resolves.
# 
# (Normally you want to block on your children instead of your parent.)
 
from com.atlassian.jira import ComponentManager
from com.atlassian.jira.issue.link import IssueLinkManager
 
ilm = ComponentManager.getInstance().getIssueLinkManager()
 
# Assume we are okay ...
result = True
 
for link in ilm.getInwardLinks(issue.getId()):
    if link.getIssueLinkType().getName() == "Parent" and link.getSourceObject().getResolution() == None:
        result = False

Feedback Welcome


Technical, Technology

Amazon Hack: Reverse Showrooming

Link: https://dannyman.toldme.com/2012/11/12/amazon-hack-reverse-showrooming/

Modern retailers have a challenge we have come to call “showrooming” where a consumer visits the local store to try out a product, then they go and order the product off Amazon.com or another retailer for less money. Some retailers will do online price matching, which is reasonable because even though that lowers their margin, they still get the sale, and can upsell you a few accessories. I saved a few dollars this way while buying a TV from Fry’s.

However, I was just browsing Amazon.com for a resin adirondack chair, where I saw:

Twenty six bucks!? Sounds good . . . not eligible for Prime, so let’s check the shipping . . .

Whiskey . . . Tango . . . Foxtrot . . . $192 shipping you say?!! Something is fishy here . . .

So, I surf on over to True Value’s web site, where the chairs are $20, and they’ll ship to the local store.

Which makes me wonder if this is a case of “reverse showrooming” . . . I go to Amazon.com because I can probably find what I am looking for, then I am led to a local retailer to save money. Very clever . . .

Feedback Welcome


Presidential Decrees

Presidential Decree #1: Black Friday

Link: https://dannyman.toldme.com/2012/11/23/presidential-decree-1-black-friday/

On the Friday immediately following Thanksgiving, no store may open any earlier than it does on any other Friday.

On Thanksgiving, a store may extend their hours beyond the time they usually close, but all customers must be offered a complimentary slice of pie, of a size not less than 1/8 of a 9″ diameter pie, and no less than 1″ deep. A store must offer either pumpkin, sweet potato, or pecan pie, but may offer additional flavors. Customers will be allowed their fill of complimentary coffee, tea, drinking water, and whipped cream.

Feedback Welcome


About Me, News and Reaction, Relationship Advice

It Wasn’t Me

Link: https://dannyman.toldme.com/2012/11/28/it-wasnt-me/

Mercury News reports Fremont man charged in tree hanging attempt:

FREMONT, Calif.—A Fremont man is facing charges that he tried to hang his girlfriend from a backyard tree.

Thirty-one-year-old Daniel Howard is scheduled to be arraigned on attempted murder and criminal threat charges on Tuesday.

Police say they found Howard Sunday evening standing behind his girlfriend, who was tied to a tree with a rope fashioned as a noose around her neck. Her hands were tied behind her back.

Howard was allegedly continuing to wrap the rope around her neck.

. . . I’m 36 years old and I live in Sunnyvale.

Feedback Welcome


About Me, News and Reaction

Also Not Me

Link: https://dannyman.toldme.com/2012/11/28/also-not-me/

Another Daniel Howard, within a week, committing a felony offense, this time in Leeds, UK:

Published on Friday 23 November 2012 06:50

A MAN who was caught growing cannabis in his cellar months after being given a suspended sentence for the same offence has been sent to jail.

Daniel Howard’s second illegal enterprise was discovered by police when they went to his home in Harehills, Leeds, looking for another person who was wanted for arrest.

Feedback Welcome


Excerpts, Letters to The Man, Technical

Collocation vs Colocation

Link: https://dannyman.toldme.com/2012/12/03/collocation-vs-colocation/

This drives me insane. Part of the challenge is that most software dictionaries are unaware of the word “colocation” and are happy to offer “collocation” as an alternative, but that is wrong wrong wrong wrong and it makes me a little nuts every time.

So, here is some explanation I just sent to the NOC and copied to the Sales team of a “Colocation Provider” who keeps sending me messages from something called “Collocation Status Report”:

Dear NOC:

A collocation is a statistic used by linguists to determine the
frequency with which words and phrases are found together.

On your contact information page, there is an option to contact Sales
about “Colocation”

Assuming that you are indeed in the business of Colocation, and not
actually updating us on the status of word frequencies, please fix the
name in your outgoing envelope from “Collocation Status Reports” to
“Colocation Status Reports”

Thanks,
-danny

Yup. That’s all I have to say about that.

1 Comment


Presidential Decrees

Presidential Decree #2: Car Alarms

Link: https://dannyman.toldme.com/2012/12/03/presidential-decree-2-car-alarms/

Audible car alarms are a public nuisance. Their use is thus prohibited, with the following exception:

The owner or operator of an automobile may actively trigger an audible car alarm if it would serve the interests of public safety. Any activation of an audible car alarm must be accompanied by a request for emergency services. Any button which triggers an audible car alarm must also send an automated distress signal to public safety authorities. If authorities do not respond in a timely fashion, concerned citizens are empowered to act on the behalf of the authorities.

If an alarm is raised in error, the responding authority must respond in one of two ways, at their discretion:

1) Use “the jaws of life” or comparable apparatus to remove or destroy the audible portion of the car alarm. If this apparatus is not available, sledge hammers, firearms, explosives and other such tools may be used, if they can be safely deployed without jeopardizing public safety.

2) Impound the automobile for not more than 90 days. Upon confiscation, all audible alarm technologies will be removed or rendered permanently inoperable, and the automobile will be made available to members of the impounding organization for their use for either official business or employee leisure.

Feedback Welcome


JIRA

JIRA Cascading Select in Jython

Link: https://dannyman.toldme.com/2012/12/06/jira-cascading-select-in-jython/

The Cascading Select Custom Field type in JIRA is a bear. The first trick is learning to set the “null” value and then the “1” child value. The next trick is building out a ModifiedValue object to hold your change. Then you get to jump down the rabbit hole of finding the correct Option values for the custom field, and setting them with the tricks just mentioned.

So, in the interests of saving me sanity next time I need to set a Cascading Select, here’s a Jython function that works in Jira 4.2:

import logging
 
from com.atlassian.jira import ComponentManager
from com.atlassian.jira.issue.customfields.manager import OptionsManager
from com.atlassian.jira.issue.customfields.view import CustomFieldParamsImpl
from com.atlassian.jira.issue import ModifiedValue
from com.atlassian.jira.issue.util import DefaultIssueChangeHolder
from java.util import HashSet
 
# cf = custom field
# issue = issue to modify
# parent = top value to set (string value)
# child = child value to set (string value)
def set_cascading_select(cf, issue, parent, child):
    # Get the managers
    cfm = ComponentManager.getInstance().getCustomFieldManager()
    om = ComponentManager.getComponentInstanceOfType(OptionsManager)
    fli = ComponentManager.getInstance().getFieldLayoutManager().getFieldLayout(issue).getFieldLayoutItem(cf)
 
    parent_options = om.getOptions(cf.getRelevantConfig(issue))
    parent_option = None
    child_option = None
    try:
        parent_option = parent_options.getOptionForValue(parent, None)
    except:
        pass
    try:
        child_option = parent_options.getOptionForValue(child, parent_option.getOptionId())
    except:
        pass
 
    if parent_option and child_option:
        old_application = issue.getCustomFieldValue(cf)
        new_application = CustomFieldParamsImpl(cf)
        a_none = HashSet()
        a_none.add(parent_option)
        a_1 = HashSet()
        a_1.add(child_option)
        new_application.put(None, a_none)
        new_application.put("1", a_1)
        mf = ModifiedValue(old_application, new_application)
        cf.updateValue(fli, issue, mf, DefaultIssueChangeHolder())
        logging.debug("set issue " + issue.getKey() + " cf " + cf.getName() + " setting " + parent + "/" + child)
        return True
    else:
        logging.error("invalid parent/child option: " + parent + "/" + child)
        return None

Example function calls from within a validation hook:

cfm = ComponentManager.getInstance().getCustomFieldManager()
 
application_cf = cfm.getCustomFieldObjectByName("Beverages")
 
# good
set_cascading_select(application_cf, issue, "Hard Drinks", "Whiskey")
# bad child
set_cascading_select(application_cf, issue, "Hard Drinks", "Coke")
# bad parent
set_cascading_select(application_cf, issue, "Soft Drinks", "Whiskey")
# total crap
set_cascading_select(application_cf, issue, "Illicit Drugs", "Bath Salts")

The logging stuff is useful for debugging, if you have that set up, else just remove those bits.

Feedback Welcome


Presidential Decrees

Presidential Decree #3: A Well-Regulated Militia

Link: https://dannyman.toldme.com/2012/12/17/presidential-decree-3-a-well-regulated-militia/

“A well regulated Militia, being necessary to the security of a free State, the right of the people to keep and bear Arms, shall not be infringed.”

You can own any firearm you want. All firearms will be stored at armories. Armories will be regulated by the ATF. Safe transportation of armaments among munitions factories and armories will be entrusted to the National Guard. Owners of firearms may store their firearms at any armories of their choice. The operation of public armories shall be funded by subscriber fees.

Firearms owners will have access to their weapons for maintenance and skills training at their armory of choice. Different armories may have different facilities for maintenance and skills training.

Licensed hunters may “check out” not more than two firearms for the duration of the hunting season. Hunters may only check out firearms suitable for their type of hunting. Firearms intended for human combat are not to be checked out.

The Military, National Guard, and Law Enforcement Agencies shall have the ability to license their agents to bear firearms for human combat. These agents must have current training on the appropriate use of these firearms to ensure public safety. Agents should be provided with sufficient access to these firearms for the performance of their duty. When not on duty, firearms will be stored at either a public armory or a private armory maintained by their employer. Agents entrusted with combat firearms must have free and immediate access to mental health services during their employment, and submit to a basic psychiatric review every three months.

In the event of a collapse in public order, state of emergency, suspension of habeas corpus, revolution, coup d’etat, military invasion or occupation, or other circumstances in which government of the people, by the people, and for the people has been compromised or forfeited, armories may release firearms for public use at their discretion.

1 Comment


Photo-a-Day

Happy Cat

Link: https://dannyman.toldme.com/2012/12/17/happy-cat/

Maxwell smiles during a belly rub.

Maxwell smiles during a belly rub.

Feedback Welcome

« Older Stuff
Arrr! . . . Avast!
Site Archive