eyce9000 / iem4j

A java library that provides a wrapper to the IBM Endpoint Manager REST API and Webreports API
Apache License 2.0
4 stars 2 forks source link

How to query the parameters of a task? #4

Closed ensean closed 9 years ago

ensean commented 9 years ago

From the definition of the Task class, it seems that we can only get task_name/task_id, is it possible to get the detailed info, such as parameters(may be included in actionscripts)

eyce9000 commented 9 years ago

I have not tried to find out the parameters of a Task before. I don't see that specified in the .bes file, so I think you may have to search through the actionscript text to figure that out.

Could use this RegEx: parameter\s"(.)"\s_of\s_action

ensean commented 9 years ago

The workaround you provide seems to be workable.

But here goes another question, how to get the actionscripts of one task?

I have not find getter method for the Class Task ...

eyce9000 commented 9 years ago

Task inherits two methods from FixletWithAction: getAction() and getDefaultAction(). Please use those to get the actions from your fixlet.

ensean commented 9 years ago

getTasks method in IEMAPI is as follows:

public List<BESAPI.Task> getTasks(String siteType,String site){
        return getBESAPIContent(buildSiteTarget(apiRoot.path("/tasks/"),siteType,site).request().get(),BESAPI.Task.class);
}

But BESAPI.Task seems not to inherits from any class...

public static class Task {

        @XmlElement(name = "Name")
        @XmlJavaTypeAdapter(NormalizedStringAdapter.class)
        @XmlSchemaType(name = "normalizedString")
        protected String name;
        @XmlElement(name = "ID")
        @XmlSchemaType(name = "nonNegativeInteger")
        protected BigInteger id;
        @XmlAttribute(name = "Resource")
        @XmlJavaTypeAdapter(NormalizedStringAdapter.class)
        @XmlSchemaType(name = "normalizedString")
        protected String resource;
        @XmlAttribute(name = "LastModified")
        @XmlJavaTypeAdapter(NormalizedStringAdapter.class)
        @XmlSchemaType(name = "normalizedString")
        protected String lastModified;

        /**
         * Gets the value of the name property.
         * 
         * @return
         *     possible object is
         *     {@link String }
         *     
         */
        public String getName() {
            return name;
        }

        /**
         * Sets the value of the name property.
         * 
         * @param value
         *     allowed object is
         *     {@link String }
         *     
         */
        public void setName(String value) {
            this.name = value;
        }

        /**
         * Gets the value of the id property.
         * 
         * @return
         *     possible object is
         *     {@link BigInteger }
         *     
         */
        public BigInteger getID() {
            return id;
        }

        /**
         * Sets the value of the id property.
         * 
         * @param value
         *     allowed object is
         *     {@link BigInteger }
         *     
         */
        public void setID(BigInteger value) {
            this.id = value;
        }

        /**
         * Gets the value of the resource property.
         * 
         * @return
         *     possible object is
         *     {@link String }
         *     
         */
        public String getResource() {
            return resource;
        }

        /**
         * Sets the value of the resource property.
         * 
         * @param value
         *     allowed object is
         *     {@link String }
         *     
         */
        public void setResource(String value) {
            this.resource = value;
        }

        /**
         * Gets the value of the lastModified property.
         * 
         * @return
         *     possible object is
         *     {@link String }
         *     
         */
        public String getLastModified() {
            return lastModified;
        }

        /**
         * Sets the value of the lastModified property.
         * 
         * @param value
         *     allowed object is
         *     {@link String }
         *     
         */
        public void setLastModified(String value) {
            this.lastModified = value;
        }

        public BESAPI.Task withName(String value) {
            setName(value);
            return this;
        }

        public BESAPI.Task withID(BigInteger value) {
            setID(value);
            return this;
        }

        public BESAPI.Task withResource(String value) {
            setResource(value);
            return this;
        }

        public BESAPI.Task withLastModified(String value) {
            setLastModified(value);
            return this;
        }

    }

I tried to cast from BESAPI.Task to Task, but failed

List<Task> taskList = (Task)client.getTasks("custom", "CGBsite");

Any suggestion?

eyce9000 commented 9 years ago

You need to do the following:

List<BESAPI.Task> taskList = client.getTasks("custom","CGBsite");
Optional<com.bigfix.schemas.bes.Task> task = client.getTask(taskList.get(0));
Action action = task.get().getDefaultAction();

Note that there is a difference betwee com.bigfix.schemas.bes.Task and BESAPI.Task.

ensean commented 9 years ago

It seems that the static class BES.Task does not exist....

eyce9000 commented 9 years ago

apologies com.bigfix.schemas.bes.Task

ensean commented 9 years ago

ooops, type mismatch for com.bigfix.schemas.bes.Task task = client.getTask(taskList.get(0));

Type mismatch: cannot convert from Optional to Task

eyce9000 commented 9 years ago

Ok, fixed that as well. This library uses google guava Optional classes in cases where a query might not return a result.

ensean commented 9 years ago

Thanks a lot for your prompt response :)