@Override public void addTagsToTestExecutions( Collection<String> tags, Collection<TestExecution> testExecutions) { for (TestExecution testExecutionItem : testExecutions) { TestExecution testExecution = testExecutionDAO.get(testExecutionItem.getId()); if (testExecution == null) { continue; } for (String tagName : tags) { if (!testExecution.getTags().contains(tagName)) { Tag tag = tagDAO.findByName(tagName); if (tag == null) { Tag newTag = new Tag(); newTag.setName(tagName); tag = tagDAO.create(newTag); } Collection<TestExecution> tagTestExecutions = tag.getTestExecutions(); if (tagTestExecutions == null) { tag.setTestExecutions(new ArrayList<>()); } tag.getTestExecutions().add(testExecution); testExecution.getTags().add(tag); } } testExecutionDAO.update(testExecution); } }
@Override @Secured public TestExecution updateTestExecution(TestExecution testExecution) throws ServiceException { TestExecution execEntity = testExecutionDAO.get(testExecution.getId()); if (execEntity == null) { throw new ServiceException("serviceException.testExecutionNotFound", testExecution.getName()); } // this is what can be updated here execEntity.setName(testExecution.getName()); execEntity.setStarted(testExecution.getStarted()); execEntity.setComment(testExecution.getComment()); execEntity.setTags(new ArrayList<>()); for (Tag tag : testExecution.getTags()) { Tag tagEntity = tagDAO.findByName(tag.getName()); if (tagEntity == null) { Tag newTag = new Tag(); newTag.setName(tag.getName()); tagEntity = tagDAO.create(newTag); } Collection<TestExecution> tagTestExecutions = tagEntity.getTestExecutions(); if (tagTestExecutions == null) { tagEntity.setTestExecutions(new ArrayList<>()); } tagEntity.getTestExecutions().add(execEntity); execEntity.getTags().add(tagEntity); } TestExecution execClone = cloneAndFetch(execEntity, true, true, true, true, true); return execClone; }
@Override public void DeleteTag(String _tag, long _itemId) { // TODO Auto-generated method stub TagDAO tDAO = new TagDAO(context); tDAO.open(); tDAO.deleteTag(new Tag(_tag, _itemId)); tDAO.close(); }
@Override public void ReturnResults() { // here we push the data to the database and to the calling activity TagDAO tDAO = new TagDAO(context); tDAO.open(); for (String tag : tags) { tDAO.createTag(tag, itemId); } tDAO.close(); listener.resultReturned(tags); }
/** * 修改帖子 * * @param topic */ public static void update(TopicBean topic, boolean updateTags) { try { beginTransaction(); if (updateTags) { TagDAO.deleteTagByRefId(topic.getId(), DiaryBean.TYPE_BBS); List tags = topic.getKeywords(); if (tags != null && tags.size() > 0) { int tag_count = 0; for (int i = 0; i < tags.size(); i++) { if (tag_count >= MAX_TAG_COUNT) break; String tag_name = (String) tags.get(i); if (tag_name.getBytes().length > MAX_TAG_LENGTH) continue; TagBean tag = new TagBean(); tag.setSite(topic.getSite()); tag.setRefId(topic.getId()); tag.setRefType(DiaryBean.TYPE_BBS); tag.setName((String) tags.get(i)); topic.getTags().add(tag); tag_count++; } } } commit(); } catch (HibernateException e) { rollback(); throw e; } }
@Override public List<String> getTagsByPrefix(String prefix) { List<String> tags = new ArrayList<String>(); for (Tag tag : tagDAO.findByPrefix(prefix)) { tags.add(tag.getName()); } return tags; }
/** * 删除帖子 * * @param topic * @throws SQLException * @throws IOException */ public static void delete(TopicOutlineBean topic) throws Exception { if (topic == null) return; Session ssn = getSession(); try { beginTransaction(); // 论坛的帖子数减一 topic.getForum().incTopicCount(-1); // 论坛的最后回帖 if (topic.getForum().getLastTopic() != null && topic.getForum().getLastTopic().getId() == topic.getId()) { topic.getForum().setLastTopic(null); topic.getForum().setLastPostTime(null); topic.getForum().setLastUsername(null); topic.getForum().setLastUser(null); } topic.getUser().getCount().incTopicCount(-1); List rpls = topic.getReplies(); for (int i = rpls.size() - 1; i >= 0; i--) { TopicReplyBean rbean = (TopicReplyBean) rpls.get(i); if (rbean.getUser() != null) rbean.getUser().getCount().incTopicReplyCount(-1); } ssn.delete(topic); // 删除标签 TagDAO.deleteTagByRefId(topic.getId(), TagBean.TYPE_BBS); // 删除附件 FCKUploadFileDAO.deleteFilesByRef( ssn, topic.getSite().getId(), topic.getId(), DiaryBean.TYPE_BBS); commit(); } catch (HibernateException e) { rollback(); throw e; } }
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setTitle("@string/edit_tags"); this.setContentView(R.layout.tag_dialog); // first we need to load our tags from the database if there are any TagDAO tDAO = new TagDAO(context); tDAO.open(); System.out.println("COLUMN NUMBER :" + itemId); List<Tag> currentTags = tDAO.getAllTagsByItemId(itemId); if (currentTags.size() > 0) { for (Tag tag : currentTags) { tags.add(tag.GetTag()); this.AddTag(tag.GetTag(), tag.GetItemId()); } } else { System.out.println("EMPTY EMPTY"); } tDAO.close(); eText = (EditText) this.findViewById(R.id.tag_eText); okButton = (Button) this.findViewById(R.id.buttonOK); doneButton = (Button) this.findViewById(R.id.buttonDone); eText.setOnEditorActionListener( new OnEditorActionListener() { @Override public boolean onEditorAction(TextView exampleView, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN) { Button okButton = (Button) findViewById(R.id.buttonOK); // TODO fix this callOnClick cause this doesnt work in certain API's okButton.callOnClick(); } return true; } }); okButton.setOnClickListener( new View.OnClickListener() { private Context context; private TagListener listener; @Override public void onClick(View arg0) { // TODO Auto-generated method stub String tagsText = eText.getText().toString().replaceAll("\\W", "").trim(); if (tagsText != null) { if (tagsText != "") { tags.add(tagsText); listener.AddTag(tagsText, itemId); eText.setText(""); } else { // alert that they left the tag blank eText.setText(""); } } else { // alert that they had an invalid entry eText.setText(""); } } public View.OnClickListener init(Context _context, TagListener _listener, long _itemId) { context = _context; listener = _listener; itemId = _itemId; return this; } }.init(context, this, itemId)); doneButton.setOnClickListener( new View.OnClickListener() { private TagListener listener; public View.OnClickListener init(TagListener _listener) { listener = _listener; return this; } @Override public void onClick(View arg0) { // TODO Auto-generated method stub eText.setOnEditorActionListener( new OnEditorActionListener() { @Override public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) { // TODO Auto-generated method stub return false; } }); String tagsText = eText.getText().toString().trim().replaceAll("\\W", "").trim(); if (tagsText != null && tagsText != "") { tags.add(tagsText); if (tags.size() > 0) { listener.ReturnResults(); dismiss(); } } else { listener.ReturnResults(); dismiss(); } } }.init(this)); }
@Override @Secured public TestExecution createTestExecution(TestExecution testExecution) throws ServiceException { // The test referred by test execution has to be an existing test Test test = testDAO.get(testExecution.getTest().getId()); testExecution.setTest(test); TestExecution storedTestExecution = testExecutionDAO.create(testExecution); // execution params if (testExecution.getParameters() != null && testExecution.getParameters().size() > 0) { for (TestExecutionParameter param : testExecution.getParameters()) { param.setTestExecution(storedTestExecution); testExecutionParameterDAO.create(param); } } // tags if (testExecution.getTags() != null && testExecution.getTags().size() > 0) { for (Tag teg : testExecution.getTags()) { Tag tag = tagDAO.findByName(teg.getName()); if (tag == null) { tag = tagDAO.create(teg); } Collection<TestExecution> tagTestExecutions = tag.getTestExecutions(); if (tagTestExecutions == null) { tag.setTestExecutions(new ArrayList<>()); } tag.getTestExecutions().add(storedTestExecution); } } // values if (testExecution.getValues() != null && !testExecution.getValues().isEmpty()) { for (Value value : testExecution.getValues()) { value.setTestExecution(storedTestExecution); if (value.getMetricName() == null) { throw new IllegalArgumentException("Metric name is mandatory"); } Metric metric = test.getMetrics() .stream() .filter(m -> m.getName().equals(value.getMetricName())) .findFirst() .get(); if (metric == null) { throw new ServiceException( "serviceException.metricNotInTest", test.getName(), test.getId().toString(), value.getMetricName()); } value.setMetric(metric); valueDAO.create(value); if (value.getParameters() != null && value.getParameters().size() > 0) { for (ValueParameter vp : value.getParameters()) { vp.setValue(value); valueParameterDAO.create(vp); } } } } TestExecution clone = cloneAndFetch(storedTestExecution, true, true, true, true, true); log.debug("Created new test execution " + clone.getId()); alertingService.processAlerts(clone); return clone; }