Project Examples
A few constants... the USER_ID must match a user's id in the database; the GROUP_ID must be 1.
public static final int USER_ID = 1; public static final int GROUP_ID = 1;
Inserting a project and getting the resulting project id...
//After the insert, we'll need the project's id ArrayList<String> meta = new ArrayList<String>(); meta.add("id"); api.setTransactionMeta(meta); // The minimum number of fields for a successful project insert DataRecord record = new DataRecord(); record.setName("project"); record.setAction(DataRecord.INSERT); record.addField("title", title); record.addField("shortDescription", "API Test Project short description"); record.addField("requestDate", new java.util.Date()); record.addField("enteredBy", USER_ID); record.addField("modifiedBy", USER_ID); record.addField("groupId", GROUP_ID); api.save(record); int newProjectId = api.getResponseValueAsInt("id");
Querying the projects and requesting the "id" and "title" fields in return; filters can optionally be set (based on the capabilities of the ProjectList class):
ArrayList<String> meta = new ArrayList<String>(); meta.add("id"); meta.add("title"); api.setTransactionMeta(meta); DataRecord record = new DataRecord(); record.setName("projectList"); record.setAction(DataRecord.SELECT); // Set the filters to query by record.addField("projectId", "$C{project.id}"); record.addField("projectsForUser", "$C{user.id}"); api.save(record); // Review the returned data (untested) ArrayList<DataRecord> projectObjects = api.getRecords(); for (DataRecord projectObject : projectObjects) { DataRecord partialProject = projectObject; // do something }
Deleting a project (must have id):
// Construct a delete request DataRecord record = new DataRecord(); record.setName("project"); record.setAction(DataRecord.DELETE); record.addField("id", partialProject.getId()); api.save(record);
Project features can be set on project insert because a project must have features. If not specified, then defaults are used.
After a project has been inserted, the features must be updated using projectFeatures. The project api does not update the features.
DataRecord record = new DataRecord(); record.setName("projectFeatures"); record.setAction(DataRecord.UPDATE); record.addField("id", projectId); record.addField("modified", new Date()); record.addField("modifiedBy", USER_ID); record.addField("showCalendar", true); record.addField("showTickets", true); record.addField("showDiscussion", false); record.addField("showPlan", true); record.addField("showLists", false); record.addField("showDocuments", false); api.save(record);
Sign in to add your comment.