From 6878f70977e2618c1a401a3b400daa53881cef7a Mon Sep 17 00:00:00 2001 From: Arkadios Tsamourliadis Date: Fri, 6 May 2016 17:04:41 +0300 Subject: [PATCH 1/8] Initial commit --- Form1.h | 720 +++++++++++++++++++++++++++++++++++++++++++++++++ IssueClass.cpp | 128 +++++++++ IssueClass.h | 51 ++++ main.cpp | 210 +++++++++++++++ 4 files changed, 1109 insertions(+) create mode 100644 Form1.h create mode 100644 IssueClass.cpp create mode 100644 IssueClass.h create mode 100644 main.cpp diff --git a/Form1.h b/Form1.h new file mode 100644 index 0000000..165cdf2 --- /dev/null +++ b/Form1.h @@ -0,0 +1,720 @@ +#include "IssueClass.h" +#include +#include + +#include "stdafx.h" +#include +#include + +#include + +#include +#include + +#pragma once + +namespace Neg_vis_01 { + + using namespace System; + using namespace System::ComponentModel; + using namespace System::Collections; + using namespace System::Windows::Forms; + using namespace System::Data; + using namespace System::Drawing; + //using namespace System::Text::RegularExpressions; + + //using namespace System::IO; + + + using namespace std; + using namespace msclr::interop; + + // for ManagedTOSTL function + // using namespace System::String; + + /// + /// Summary for Form1 + /// + public ref class Form1 : public System::Windows::Forms::Form + { + public: + Form1(void) + { + InitializeComponent(); + // + //TODO: Add the constructor code here + // + } + + protected: + /// + /// Clean up any resources being used. + /// + ~Form1() + { + if (components) + { + delete components; + } + } + private: System::Windows::Forms::SplitContainer^ splitContainer1; + private: System::Windows::Forms::Button^ button3; + + protected: + + private: System::Windows::Forms::TextBox^ textBox1; + private: System::Windows::Forms::Button^ button2; + private: System::Windows::Forms::Button^ button1; + private: System::Windows::Forms::MaskedTextBox^ maskedTextBox3; + private: System::Windows::Forms::MaskedTextBox^ maskedTextBox2; + private: System::Windows::Forms::Label^ issueNumLabel; + private: System::Windows::Forms::MaskedTextBox^ maskedTextBox1; + private: System::Windows::Forms::Label^ label2; + private: System::Windows::Forms::Label^ label3; + private: System::Windows::Forms::Label^ label4; + private: System::Windows::Forms::Label^ label7; + private: System::Windows::Forms::Label^ label6; + private: System::Windows::Forms::Label^ label5; + private: System::Windows::Forms::Button^ button4; + private: System::Windows::Forms::MaskedTextBox^ maskedTextBox4; + private: System::Windows::Forms::Panel^ panel1; + private: System::Windows::Forms::Label^ issueNumLabel1; + private: System::Windows::Forms::TextBox^ ResultsTextBox; + + private: System::Windows::Forms::Label^ issueNumLabel0; + private: System::Windows::Forms::Label^ label9; + private: System::Windows::Forms::Label^ issueChild; + + private: System::Windows::Forms::Panel^ panel2; + private: System::Windows::Forms::Panel^ panel3; + private: System::Windows::Forms::Label^ parentIssue; + private: System::Windows::Forms::Label^ issueNumLabel2; + private: System::Windows::Forms::Label^ label8; + private: System::Windows::Forms::Label^ issueNumLabel3; + private: System::Windows::Forms::TextBox^ textBox2; + + private: + /// + /// Required designer variable. + /// + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + void InitializeComponent(void) + { + this->splitContainer1 = (gcnew System::Windows::Forms::SplitContainer()); + this->parentIssue = (gcnew System::Windows::Forms::Label()); + this->issueNumLabel2 = (gcnew System::Windows::Forms::Label()); + this->label8 = (gcnew System::Windows::Forms::Label()); + this->panel3 = (gcnew System::Windows::Forms::Panel()); + this->label7 = (gcnew System::Windows::Forms::Label()); + this->label6 = (gcnew System::Windows::Forms::Label()); + this->label5 = (gcnew System::Windows::Forms::Label()); + this->textBox1 = (gcnew System::Windows::Forms::TextBox()); + this->button3 = (gcnew System::Windows::Forms::Button()); + this->panel1 = (gcnew System::Windows::Forms::Panel()); + this->issueNumLabel1 = (gcnew System::Windows::Forms::Label()); + this->button4 = (gcnew System::Windows::Forms::Button()); + this->ResultsTextBox = (gcnew System::Windows::Forms::TextBox()); + this->issueNumLabel0 = (gcnew System::Windows::Forms::Label()); + this->label9 = (gcnew System::Windows::Forms::Label()); + this->panel2 = (gcnew System::Windows::Forms::Panel()); + this->label3 = (gcnew System::Windows::Forms::Label()); + this->label2 = (gcnew System::Windows::Forms::Label()); + this->maskedTextBox3 = (gcnew System::Windows::Forms::MaskedTextBox()); + this->maskedTextBox2 = (gcnew System::Windows::Forms::MaskedTextBox()); + this->issueNumLabel = (gcnew System::Windows::Forms::Label()); + this->maskedTextBox1 = (gcnew System::Windows::Forms::MaskedTextBox()); + this->maskedTextBox4 = (gcnew System::Windows::Forms::MaskedTextBox()); + this->label4 = (gcnew System::Windows::Forms::Label()); + this->issueChild = (gcnew System::Windows::Forms::Label()); + this->button2 = (gcnew System::Windows::Forms::Button()); + this->button1 = (gcnew System::Windows::Forms::Button()); + this->issueNumLabel3 = (gcnew System::Windows::Forms::Label()); + this->textBox2 = (gcnew System::Windows::Forms::TextBox()); + (cli::safe_cast(this->splitContainer1))->BeginInit(); + this->splitContainer1->Panel1->SuspendLayout(); + this->splitContainer1->Panel2->SuspendLayout(); + this->splitContainer1->SuspendLayout(); + this->panel3->SuspendLayout(); + this->panel1->SuspendLayout(); + this->panel2->SuspendLayout(); + this->SuspendLayout(); + // + // splitContainer1 + // + this->splitContainer1->Dock = System::Windows::Forms::DockStyle::Fill; + this->splitContainer1->Location = System::Drawing::Point(0, 0); + this->splitContainer1->Name = L"splitContainer1"; + // + // splitContainer1.Panel1 + // + this->splitContainer1->Panel1->Controls->Add(this->parentIssue); + this->splitContainer1->Panel1->Controls->Add(this->issueNumLabel2); + this->splitContainer1->Panel1->Controls->Add(this->label8); + this->splitContainer1->Panel1->Controls->Add(this->panel3); + this->splitContainer1->Panel1->Controls->Add(this->panel1); + this->splitContainer1->Panel1->Controls->Add(this->panel2); + this->splitContainer1->Panel1->Controls->Add(this->maskedTextBox4); + this->splitContainer1->Panel1->Controls->Add(this->label4); + this->splitContainer1->Panel1->Controls->Add(this->issueChild); + this->splitContainer1->Panel1->Controls->Add(this->button2); + this->splitContainer1->Panel1->Controls->Add(this->button1); + this->splitContainer1->Panel1->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::splitContainer1_Panel1_Paint); + // + // splitContainer1.Panel2 + // + this->splitContainer1->Panel2->Controls->Add(this->issueNumLabel3); + this->splitContainer1->Panel2->Controls->Add(this->textBox2); + this->splitContainer1->Size = System::Drawing::Size(717, 428); + this->splitContainer1->SplitterDistance = 433; + this->splitContainer1->TabIndex = 0; + // + // parentIssue + // + this->parentIssue->AutoSize = true; + this->parentIssue->Location = System::Drawing::Point(276, 91); + this->parentIssue->Name = L"parentIssue"; + this->parentIssue->Size = System::Drawing::Size(0, 13); + this->parentIssue->TabIndex = 21; + // + // issueNumLabel2 + // + this->issueNumLabel2->AutoSize = true; + this->issueNumLabel2->Location = System::Drawing::Point(177, 91); + this->issueNumLabel2->Name = L"issueNumLabel2"; + this->issueNumLabel2->Size = System::Drawing::Size(93, 13); + this->issueNumLabel2->TabIndex = 20; + this->issueNumLabel2->Text = L"parent issue name"; + // + // label8 + // + this->label8->AutoSize = true; + this->label8->Location = System::Drawing::Point(289, 63); + this->label8->Name = L"label8"; + this->label8->Size = System::Drawing::Size(87, 13); + this->label8->TabIndex = 19; + this->label8->Text = L"subissue counter"; + // + // panel3 + // + this->panel3->Controls->Add(this->label7); + this->panel3->Controls->Add(this->label6); + this->panel3->Controls->Add(this->label5); + this->panel3->Controls->Add(this->textBox1); + this->panel3->Controls->Add(this->button3); + this->panel3->Location = System::Drawing::Point(4, 112); + this->panel3->Name = L"panel3"; + this->panel3->Size = System::Drawing::Size(219, 316); + this->panel3->TabIndex = 18; + // + // label7 + // + this->label7->AutoSize = true; + this->label7->Location = System::Drawing::Point(127, 6); + this->label7->Name = L"label7"; + this->label7->Size = System::Drawing::Size(49, 13); + this->label7->TabIndex = 13; + this->label7->Text = L"P 2 Rate"; + // + // label6 + // + this->label6->AutoSize = true; + this->label6->Location = System::Drawing::Point(72, 6); + this->label6->Name = L"label6"; + this->label6->Size = System::Drawing::Size(49, 13); + this->label6->TabIndex = 12; + this->label6->Text = L"P 1 Rate"; + // + // label5 + // + this->label5->AutoSize = true; + this->label5->Location = System::Drawing::Point(9, 6); + this->label5->Name = L"label5"; + this->label5->Size = System::Drawing::Size(32, 13); + this->label5->TabIndex = 11; + this->label5->Text = L"Issue"; + // + // textBox1 + // + this->textBox1->Location = System::Drawing::Point(3, 22); + this->textBox1->Multiline = true; + this->textBox1->Name = L"textBox1"; + this->textBox1->ScrollBars = System::Windows::Forms::ScrollBars::Vertical; + this->textBox1->Size = System::Drawing::Size(213, 267); + this->textBox1->TabIndex = 6; + // + // button3 + // + this->button3->Cursor = System::Windows::Forms::Cursors::Arrow; + this->button3->Location = System::Drawing::Point(0, 295); + this->button3->Name = L"button3"; + this->button3->Size = System::Drawing::Size(65, 21); + this->button3->TabIndex = 7; + this->button3->Text = L"From file"; + this->button3->UseVisualStyleBackColor = true; + this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click); + // + // panel1 + // + this->panel1->Controls->Add(this->issueNumLabel1); + this->panel1->Controls->Add(this->button4); + this->panel1->Controls->Add(this->ResultsTextBox); + this->panel1->Controls->Add(this->issueNumLabel0); + this->panel1->Controls->Add(this->label9); + this->panel1->Location = System::Drawing::Point(229, 115); + this->panel1->Name = L"panel1"; + this->panel1->Size = System::Drawing::Size(201, 313); + this->panel1->TabIndex = 17; + // + // issueNumLabel1 + // + this->issueNumLabel1->AutoSize = true; + this->issueNumLabel1->Location = System::Drawing::Point(124, 51); + this->issueNumLabel1->Name = L"issueNumLabel1"; + this->issueNumLabel1->Size = System::Drawing::Size(40, 13); + this->issueNumLabel1->TabIndex = 16; + this->issueNumLabel1->Text = L"Party 2"; + // + // button4 + // + this->button4->Cursor = System::Windows::Forms::Cursors::Arrow; + this->button4->Location = System::Drawing::Point(55, 3); + this->button4->Name = L"button4"; + this->button4->Size = System::Drawing::Size(63, 45); + this->button4->TabIndex = 15; + this->button4->Text = L"Resolve Issues"; + this->button4->UseVisualStyleBackColor = true; + this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click); + // + // ResultsTextBox + // + this->ResultsTextBox->Location = System::Drawing::Point(6, 66); + this->ResultsTextBox->Multiline = true; + this->ResultsTextBox->Name = L"ResultsTextBox"; + this->ResultsTextBox->ReadOnly = true; + this->ResultsTextBox->ScrollBars = System::Windows::Forms::ScrollBars::Vertical; + this->ResultsTextBox->Size = System::Drawing::Size(192, 238); + this->ResultsTextBox->TabIndex = 16; + // + // issueNumLabel0 + // + this->issueNumLabel0->AutoSize = true; + this->issueNumLabel0->Location = System::Drawing::Point(58, 51); + this->issueNumLabel0->Name = L"issueNumLabel0"; + this->issueNumLabel0->Size = System::Drawing::Size(40, 13); + this->issueNumLabel0->TabIndex = 16; + this->issueNumLabel0->Text = L"Party 1"; + // + // label9 + // + this->label9->AutoSize = true; + this->label9->Location = System::Drawing::Point(3, 51); + this->label9->Name = L"label9"; + this->label9->Size = System::Drawing::Size(32, 13); + this->label9->TabIndex = 13; + this->label9->Text = L"Issue"; + // + // panel2 + // + this->panel2->Controls->Add(this->label3); + this->panel2->Controls->Add(this->label2); + this->panel2->Controls->Add(this->maskedTextBox3); + this->panel2->Controls->Add(this->maskedTextBox2); + this->panel2->Controls->Add(this->issueNumLabel); + this->panel2->Controls->Add(this->maskedTextBox1); + this->panel2->Location = System::Drawing::Point(120, 3); + this->panel2->Name = L"panel2"; + this->panel2->Size = System::Drawing::Size(244, 55); + this->panel2->TabIndex = 16; + // + // label3 + // + this->label3->AutoSize = true; + this->label3->Location = System::Drawing::Point(155, 12); + this->label3->Name = L"label3"; + this->label3->Size = System::Drawing::Size(66, 13); + this->label3->TabIndex = 9; + this->label3->Text = L"Party 2 Rate"; + // + // label2 + // + this->label2->AutoSize = true; + this->label2->Location = System::Drawing::Point(83, 12); + this->label2->Name = L"label2"; + this->label2->Size = System::Drawing::Size(66, 13); + this->label2->TabIndex = 8; + this->label2->Text = L"Party 1 Rate"; + // + // maskedTextBox3 + // + this->maskedTextBox3->Location = System::Drawing::Point(172, 32); + this->maskedTextBox3->Name = L"maskedTextBox3"; + this->maskedTextBox3->Size = System::Drawing::Size(23, 20); + this->maskedTextBox3->TabIndex = 3; + // + // maskedTextBox2 + // + this->maskedTextBox2->Location = System::Drawing::Point(106, 32); + this->maskedTextBox2->Name = L"maskedTextBox2"; + this->maskedTextBox2->Size = System::Drawing::Size(26, 20); + this->maskedTextBox2->TabIndex = 2; + // + // issueNumLabel + // + this->issueNumLabel->AutoSize = true; + this->issueNumLabel->Location = System::Drawing::Point(5, 12); + this->issueNumLabel->Name = L"issueNumLabel"; + this->issueNumLabel->Size = System::Drawing::Size(72, 13); + this->issueNumLabel->TabIndex = 1; + this->issueNumLabel->Text = L"Issue Number"; + // + // maskedTextBox1 + // + this->maskedTextBox1->Location = System::Drawing::Point(17, 32); + this->maskedTextBox1->Name = L"maskedTextBox1"; + this->maskedTextBox1->Size = System::Drawing::Size(51, 20); + this->maskedTextBox1->TabIndex = 0; + // + // maskedTextBox4 + // + this->maskedTextBox4->Location = System::Drawing::Point(120, 79); + this->maskedTextBox4->Name = L"maskedTextBox4"; + this->maskedTextBox4->Size = System::Drawing::Size(51, 20); + this->maskedTextBox4->TabIndex = 14; + // + // label4 + // + this->label4->AutoSize = true; + this->label4->Location = System::Drawing::Point(177, 63); + this->label4->Name = L"label4"; + this->label4->Size = System::Drawing::Size(37, 13); + this->label4->TabIndex = 10; + this->label4->Text = L"Issues"; + // + // issueChild + // + this->issueChild->AutoSize = true; + this->issueChild->Location = System::Drawing::Point(377, 63); + this->issueChild->Name = L"issueChild"; + this->issueChild->Size = System::Drawing::Size(13, 13); + this->issueChild->TabIndex = 12; + this->issueChild->Text = L"0"; + // + // button2 + // + this->button2->Location = System::Drawing::Point(3, 63); + this->button2->Name = L"button2"; + this->button2->Size = System::Drawing::Size(115, 41); + this->button2->TabIndex = 5; + this->button2->Text = L"add subissues to issue..."; + this->button2->UseVisualStyleBackColor = true; + this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click); + // + // button1 + // + this->button1->ForeColor = System::Drawing::SystemColors::ControlText; + this->button1->Location = System::Drawing::Point(3, 15); + this->button1->Name = L"button1"; + this->button1->Size = System::Drawing::Size(115, 29); + this->button1->TabIndex = 4; + this->button1->Text = L"save issue"; + this->button1->UseVisualStyleBackColor = true; + this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click); + // + // issueNumLabel3 + // + this->issueNumLabel3->AutoSize = true; + this->issueNumLabel3->Location = System::Drawing::Point(5, 45); + this->issueNumLabel3->Name = L"issueNumLabel3"; + this->issueNumLabel3->Size = System::Drawing::Size(63, 13); + this->issueNumLabel3->TabIndex = 1; + this->issueNumLabel3->Text = L"calculations"; + // + // textBox2 + // + this->textBox2->Location = System::Drawing::Point(8, 63); + this->textBox2->Multiline = true; + this->textBox2->Name = L"textBox2"; + this->textBox2->ReadOnly = true; + this->textBox2->ScrollBars = System::Windows::Forms::ScrollBars::Both; + this->textBox2->Size = System::Drawing::Size(269, 353); + this->textBox2->TabIndex = 0; + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(717, 428); + this->Controls->Add(this->splitContainer1); + this->Name = L"Form1"; + this->Text = L"Negotiation 1.0 GUI"; + this->splitContainer1->Panel1->ResumeLayout(false); + this->splitContainer1->Panel1->PerformLayout(); + this->splitContainer1->Panel2->ResumeLayout(false); + this->splitContainer1->Panel2->PerformLayout(); + (cli::safe_cast(this->splitContainer1))->EndInit(); + this->splitContainer1->ResumeLayout(false); + this->panel3->ResumeLayout(false); + this->panel3->PerformLayout(); + this->panel1->ResumeLayout(false); + this->panel1->PerformLayout(); + this->panel2->ResumeLayout(false); + this->panel2->PerformLayout(); + this->ResumeLayout(false); + + } +#pragma endregion + + private: int currentParent; + private: + static System::Collections::Generic::List ^issues + = gcnew System::Collections::Generic::List(); + +/////////////////////////////////////////////////////////////////////////////////////////////////////// +private: System::String^ CalculateNormRates(System::Collections::Generic::List ^issues) +{ + //ofstream outResultFile( "result.txt", ios::app ); + double p1sum=0; + double p2sum=0; + IssueClass* ptrtmpIssue; + System::String^ calcTextBox=""; + + for (int i=0; iCount; i++) + { + ptrtmpIssue = reinterpret_cast (issues[i].ToPointer()); + p1sum += ptrtmpIssue->getP1Rate(); + p2sum += ptrtmpIssue->getP2Rate(); + /////////////////////////// + + System::String^ tmpIsnum= gcnew String(ptrtmpIssue->IssueNum.c_str()); + calcTextBox=calcTextBox+"Calculating SumS p1, p2: "+p1sum+", "+p2sum+"\r\n"; + calcTextBox=calcTextBox+" Issue name: "+tmpIsnum+" rates: "+ptrtmpIssue->getP1Rate()+" "+ptrtmpIssue->getP2Rate()+"\r\n"; + } + //cout<<"\nSum of Party 1 Rates:"<Count; i++) { + ptrtmpIssue = reinterpret_cast (issues[i].ToPointer()); + ptrtmpIssue->normalizeRates(p1sum, p2sum); + //cout<<"Normalized rates for Issue"<IssueNum.c_str()); + calcTextBox=calcTextBox+"\r\nNormalized rates for Issue "+tmpIsnum+" : "+ + ptrtmpIssue->getP1Rate()+", "+ptrtmpIssue->getP2Rate()+"\r\n"; + + } + return calcTextBox; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////// +private: void resolveIssues(System::Collections::Generic::List ^issues) +{ + //ofstream outResultFile( "result.txt", ios::app ); + + IssueClass* ptrtmpIssue; + + //At each iteration an Issue will be Resolved + for (int genIndex=0; genIndex < issues->Count; genIndex++) + { + double maxDiff=0; + int maxDiffIssueIndex; + + //Find an Issue to Resolve + for (int i=0; iCount; i++) + { + ptrtmpIssue = reinterpret_cast (issues[i].ToPointer()); + if (ptrtmpIssue->Resolved()) + { //Issue already Resolved + continue; + } + if ( ptrtmpIssue->getMrkDiff() >= maxDiff ) + { + maxDiff = ptrtmpIssue->getMrkDiff(); + maxDiffIssueIndex = i; + } + } + ptrtmpIssue = reinterpret_cast (issues[maxDiffIssueIndex].ToPointer()); + ptrtmpIssue->setWinningParty(); //This Issue has just been resolved + + + System::String^ tmptextbox=""; + tmptextbox = tmptextbox+"\r\nIssue "+ptrtmpIssue->getIssueNum()+ + " won by party "+ptrtmpIssue->getParty()+"\r\n"; + textBox2->Text +=tmptextbox; + //outResultFile<<"\nIssue "<Count; i++) + { + ptrtmpIssue = reinterpret_cast (issues[i].ToPointer()); + if (ptrtmpIssue->Resolved()) + { //Does not have to Calculate new Rates for a resolved Issue + continue; + } + + IssueClass* ptrtmpIssuemaxDiffIssueIndex = reinterpret_cast (issues[maxDiffIssueIndex].ToPointer());; + + string tmpstringtextbox = ptrtmpIssue->CalculateNewRates ( ptrtmpIssuemaxDiffIssueIndex->getWiningPartyRate(), + ptrtmpIssuemaxDiffIssueIndex->getLoosingPartyRate(), + ptrtmpIssuemaxDiffIssueIndex->getParty() ); + System::String^ tmptextbox= gcnew String(tmpstringtextbox.c_str()); + textBox2->Text +=tmptextbox; + } + }// end of for( genIndex + +} + +//save issue +private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { + IssueClass* ptrtmpIssue; + if(this->issueChild->Text=="1") {//prwto paidi + ptrtmpIssue = reinterpret_cast (issues[currentParent].ToPointer()); + ptrtmpIssue->alterToSubIssue( marshal_as(this->parentIssue->Text)+","+ + marshal_as(this->maskedTextBox1->Text), + marshal_as(this->maskedTextBox2->Text), + marshal_as(this->maskedTextBox3->Text) ); + //Kratame ton ari8mo tou paidiou sto Label issueChild, xrhsimopoiontas to ws counter + std::istringstream chldTxt; + double chldDbl; + chldTxt.str(marshal_as(this->issueChild->Text)); + chldTxt>>chldDbl; + chldDbl++; + this->issueChild->Text = System::Convert::ToString(chldDbl); + //currentParent=IssueIndex; + } + else if(this->issueChild->Text=="0") {//kanonikh eisagwgh + ptrtmpIssue = new IssueClass( + marshal_as(this->maskedTextBox1->Text), + marshal_as(this->maskedTextBox2->Text), + marshal_as(this->maskedTextBox3->Text) ); + issues->Add(System::IntPtr(ptrtmpIssue)); + } + else {//eisagwgh deuerou paidiou kai meta + ptrtmpIssue = new IssueClass( marshal_as(this->parentIssue->Text)+","+ + marshal_as(this->maskedTextBox1->Text), + marshal_as(this->maskedTextBox2->Text), + marshal_as(this->maskedTextBox3->Text) ); + issues->Add(System::IntPtr(ptrtmpIssue)); + //Kratame ton ari8mo tou paidiou sto Label issueChild, xrhsimopoiontas to ws counter + std::istringstream chldTxt; + double chldDbl; + chldTxt.str(marshal_as(this->issueChild->Text)); + chldTxt>>chldDbl; + chldDbl++; + this->issueChild->Text = System::Convert::ToString(chldDbl); + //currentParent=IssueIndex; + + } + + //!!!!!!!se periptwsh prwtou paidiou na diagrafetai o goneas apo to textbox!!!<--add + + + //Convert the string + String^ MSIssueNum = gcnew String(ptrtmpIssue->IssueNum.c_str()); + this->textBox1->Text+=MSIssueNum+"\t\t" + +this->maskedTextBox2->Text+"\t"+this->maskedTextBox3->Text+"\r\n"; + this->maskedTextBox1->Clear(); + this->maskedTextBox2->Clear(); + this->maskedTextBox3->Clear(); + + } + + //add subissues to issue... +private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { + this->issueChild->Text="0"; + //this->maskedTextBox1->Hide(); + + bool foundFlag=0; + int IssueIndex; + for (IssueIndex=0; IssueIndexCount; IssueIndex++) + { + IssueClass* ptrtmpIssue = reinterpret_cast (issues[IssueIndex].ToPointer()); + if (this->maskedTextBox4->Text==ptrtmpIssue->getIssueNum()) { + foundFlag=1; break; } + } + //Not found an issue with Inum IssueNum + if (!foundFlag) + { + this->label4->Text="No such Issue found "; //+this->maskedTextBox4->Text; + this->maskedTextBox2->Clear(); + this->maskedTextBox3->Clear(); + this->maskedTextBox4->Clear(); + return; + } + this->label4->Text="subissues"; + this->parentIssue->Text=this->maskedTextBox4->Text; + //Kratame ton ari8mo tou paidiou sto Label issueChild, xrhsimopoiontas to ws counter + std::istringstream chldTxt; + double chldDbl; + chldTxt.str(marshal_as(this->issueChild->Text)); + chldTxt>>chldDbl; + chldDbl++; + this->issueChild->Text = System::Convert::ToString(chldDbl); + currentParent=IssueIndex; + } + + //From file +private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) { + OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog; + if(openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK) + { + System::IO::StreamReader ^ sr = gcnew + System::IO::StreamReader(openFileDialog1->FileName); + IssueClass* ptrtmpIssue; + while(sr->Peek()>=0) { + String ^line = sr->ReadLine(); + this->textBox1->Text+=line+"\r\n"; + array^chars = {'\t'}; + array^ s = line->Split( chars ); + String^ s1=s[0]; + String^ p1=s[1]; + String^ p2=s[2]; + ptrtmpIssue = new IssueClass( marshal_as(s1), + marshal_as(p1), marshal_as(p2) ); + issues->Add(System::IntPtr(ptrtmpIssue)); + } + //MessageBox::Show(sr->ReadToEnd()); + sr->Close(); + } + + } +private: System::Void splitContainer1_Panel1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) { + } + + //Resolve Issues +private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) { + textBox2->Text = CalculateNormRates(issues); + //issues->Order( + resolveIssues(issues); + + IssueClass* ptrtmpIssue; + + //Printing final results + for (int i=0; iCount; i++) + { + ptrtmpIssue = reinterpret_cast (issues[i].ToPointer()); + //ptrtmpIssue->printIssueDetails(); + + System::String^ TextBoxString = gcnew System::String(ptrtmpIssue->IssueNum.c_str()); + + if ( ptrtmpIssue->getParty()==1 ) + ResultsTextBox->Text=ResultsTextBox->Text+TextBoxString+"\t\t"+"1"+"\t"+"0"+"\r\n"; + else if ( ptrtmpIssue->getParty()==2 ) + ResultsTextBox->Text=ResultsTextBox->Text+TextBoxString+"\t\t"+"0"+"\t"+"1"+"\r\n"; + else + ResultsTextBox->Text=ResultsTextBox->Text+TextBoxString+"\r\n"; + } + + } +}; +} + diff --git a/IssueClass.cpp b/IssueClass.cpp new file mode 100644 index 0000000..a162b97 --- /dev/null +++ b/IssueClass.cpp @@ -0,0 +1,128 @@ +#include "IssueClass.h" +#include +#include +#include +#include + +using namespace std; + +unsigned int IssueClass::IssuesCnt; //<---Need this?? + +/////////////////////////////////////////////////////////////////////////////////////////////////////// +void IssueClass::CalculateNewRates(double WinnersResolvedIssueRate, double LoosersResolvedIssueRate, int WinningParty ) +{ + ofstream outResultFile( "result.txt", ios::app ); + cout<<"Old Rates for Issue "<= 0 && Difference < 30 ) Factor = (1.0/0.3) * Difference; + else if ( Difference >=30 && Difference <= 100 ) Factor = 100; + } + else if (WinningIssueRate > 10 && WinningIssueRate <= 20 ) + { + if( Difference >= 0 && Difference < 10 ) Factor = 1.25 * Difference + 12.5; + else if( Difference >= 10 && Difference < 20 ) Factor = 25; + else if( Difference >= 20 && Difference < 40 ) Factor = ( 1.0 / 2.0 ) * Difference + 15; + else if( Difference >= 40 && Difference < 60 ) Factor = - ( 3.5 / 2.0 ) * Difference + 105; + else if( Difference >= 60 && Difference <= 100 ) Factor = - ( 0.5 / 4.0 ) * Difference + 7.5; + } + else if ( WinningIssueRate > 20 && WinningIssueRate <= 35 ) + { + if( Difference >= 0 && Difference < 10 ) Factor = 5; + else if( Difference >= 10 && Difference < 20 ) Factor = 0.75 * Difference - 2.5; + else if( Difference >= 20 && Difference < 40 ) Factor = 12.5; + else if( Difference >= 40 && Difference < 60 ) Factor = - ( 2.5 / 4.0 ) * Difference + 37.5; + else if( Difference >= 60 && Difference <= 100 ) Factor = - ( 1.0 / 4.0 ) * Difference + 15; + } + else if( WinningIssueRate > 35 && WinningIssueRate <= 55 ) { + if( Difference >= 0 && Difference < 10 ) Factor = ( 1.0 / 1.0 ) * Difference - 5; + else if( Difference >= 10 && Difference < 20 ) Factor = 5; + else if( Difference >= 20 && Difference < 40 ) Factor = - ( 0.5 / 1.0 ) * Difference + 20; + else if( Difference >= 40 && Difference <= 100 ) Factor = - 0.25 * Difference + 10; + } + else if( WinningIssueRate > 55 ) + { + if( Difference >= 0 && Difference <= 100 ) Factor = ( 1.0 / 1.0 ) * Difference - 100; + } + + return Factor/100.0; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////// +double IssueClass::CalculateLoosingPartyRate(double WinningIssueRate, double Difference) const +{ + double Factor; + if ( WinningIssueRate <= 10 ) + { + if( Difference >= 0 && Difference < 20 ) Factor = 25; + else if( Difference >= 20 && Difference < 30 ) Factor = ( 2.5 / 1.0 ) * Difference - 25; + else if( Difference >= 30 && Difference <= 100) Factor = 50; + } + else if (WinningIssueRate > 10 && WinningIssueRate <= 20 ) + { + if( Difference >= 0 && Difference < 30 ) Factor = 25; + else if( Difference >= 30 && Difference <= 100 ) Factor = -( 2.5 / 7.0 ) * Difference + 250 / 7; + } + else if ( WinningIssueRate > 20 && WinningIssueRate <= 35 ) + { + if( Difference >= 0 && Difference < 40 ) Factor = 50; + else if( Difference >= 40 && Difference < 50 ) Factor = -( 2.5 / 1.0 ) * Difference + 150; + else if( Difference >= 50 && Difference <= 100 ) Factor = -( 0.5 / 1.0 ) * Difference + 50; + } + else if( WinningIssueRate > 35 && WinningIssueRate <= 55 ) { + if( Difference >= 0 && Difference < 20 ) Factor = 75; + else if( Difference >= 20 && Difference < 30 ) Factor = -( 2.5 / 1.0 ) * Difference + 125; + else if( Difference >= 30 && Difference < 55 ) Factor = 50; + else if( Difference >= 55 && Difference < 60 ) Factor = -5 * Difference + 325; + else if( Difference >= 60 && Difference <= 100 ) Factor = -( 2.5 / 4.0 ) * Difference + 62.5; + } + else if( WinningIssueRate > 55 ) + { + if( Difference >= 0 && Difference < 30 ) Factor = 100; + else if( Difference >= 30 && Difference < 40 ) Factor = -( 2.5 / 1.0 ) * Difference + 175; + else if( Difference >= 40 && Difference < 50 ) Factor = 75; + else if( Difference >= 50 && Difference < 60 ) Factor = -( 2.5 / 1.0 ) * Difference + 200; + else if( Difference >= 60 && Difference <= 100 ) Factor = -( 5.0 / 4.0 ) * Difference + 125; + } + + return Factor/100.0; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////// +void IssueClass::printIssueDetails() +{ + ofstream outResultFile( "result.txt", ios::app ); + cout<<"Issue "< +#include + +using namespace std; + +class IssueClass +{ + +private: + enum Party { NOPARTY, PARTY_1, PARTY_2 } IssueBelongs; + static unsigned int IssuesCnt; //<---Need this?? + double p1_rate; + double p2_rate; + double CalculateWinningPartyRate(double, double) const; + double CalculateLoosingPartyRate(double, double) const; + +public: + //IssueClass() {} + ~IssueClass() {IssuesCnt--;}//<---Need this?? + IssueClass(string INum, double m1, double m2) : + p1_rate(m1), p2_rate(m2), IssueNum(INum), IssueBelongs(NOPARTY) + { IssuesCnt++; }//<---Need this?? + void alterToSubIssue(string chldNum, double m1, double m2) { IssueNum=IssueNum+","+chldNum; p1_rate=m1; p2_rate=m2; } + double getMrkDiff() { if( p1_rate>p2_rate ) return p1_rate-p2_rate; + else return p2_rate-p1_rate; } + void setWinningParty() { if( p1_rate>p2_rate ) IssueBelongs=PARTY_1; + else IssueBelongs=PARTY_2; } + double getWiningPartyRate() { if ( IssueBelongs == PARTY_1 ) return p1_rate; + else return p2_rate; } + double getLoosingPartyRate() { if ( IssueBelongs == PARTY_1 ) return p2_rate; + else return p1_rate; } + bool Resolved() const { if (IssueBelongs==NOPARTY) return false; else return true; } + int getParty() const { /*if (IssueBelongs==NOPARTY) return 0; + else if (IssueBelongs==PARTY_1) return 1; + else return 2;*/ return IssueBelongs; } + void normalizeRates(double p1sum, double p2sum) { p1_rate=100.0*p1_rate/p1sum; p2_rate=100.0*p2_rate/p2sum; } + string getIssueNum() const { return IssueNum; } + double getP1Rate() const { return p1_rate; } + double getP2Rate() const { return p2_rate; } + + void printIssueDetails(); + void CalculateNewRates(double, double, int); + ///////////////////// + string IssueNum; +}; + + +#endif \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..8fd295f --- /dev/null +++ b/main.cpp @@ -0,0 +1,210 @@ +#include "IssueClass.h" +#include +#include +#include +#include +#include + +using namespace std; + +void resolveIssues(vector< IssueClass >&); +void printResult(vector< IssueClass >&); +void CalculateNormRates(vector< IssueClass >&); + +int main() +{ + //////////////////////////////////////////// + // ofstream outMeta1tFile( "metadata1.txt", ios::app ); + + + vector< IssueClass > issues; + + unsigned int IssuesCnt=0; //<---Need this?? + string Inum; + double p1Rate; + double p2Rate; + + //Initial issues input + cout<<"Give Issues info, or Type '0' instate of to continue"<, then , then :"<>Inum; + //cout<<"before if"<>p1Rate; + //cout<<"after cin p1"<>p2Rate; + //cout<<"after cin p2"< or Type '0' to continue"< that should be divided"<>Inum; + if (Inum=="0") break; + + int IssueIndex=-1; + for (IssueIndex=0; IssueIndex, , then "<>childIssueNum>>p1Rate>>p2Rate; + issues[IssueIndex].alterToSubIssue( childIssueNum, p1Rate, p2Rate ); + //////////////////////// + // outMeta1tFile<<"Alter to subissue child issue name: "<, , then "<>childIssueNum; + if (childIssueNum=="0") + break; + cin>>p1Rate>>p2Rate; + IssueClass tmpIssue( parentIssueNum+","+childIssueNum, p1Rate, p2Rate ); + ////////////////////////////////////// + // outMeta1tFile<<"child issue name: "<>a; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////// +void resolveIssues(vector< IssueClass >& issues) +{ + ofstream outResultFile( "result.txt", ios::app ); + //At each iteration an Issue will be Resolved + for (unsigned int genIndex=0; genIndex < issues.size(); genIndex++) + { + double maxDiff=0; + unsigned int maxDiffIssueIndex; + + //Find an Issue to Resolve + for (unsigned int i=0; i= maxDiff ) + { + maxDiff = issues[i].getMrkDiff(); + maxDiffIssueIndex = i; + } + } + issues[maxDiffIssueIndex].setWinningParty(); //This Issue has just been resolved + cout<<"\nIssue "<& issues) +{ + ofstream outResultFile( "result.txt", ios::app ); + double p1sum=0; + double p2sum=0; + + for (unsigned int i=0; i& issues) +{ + cout<<"Results of Resolved Issues"< Date: Fri, 6 May 2016 17:50:35 +0300 Subject: [PATCH 2/8] 1st database configuration --- nb-configuration.xml | 18 ++++++++ .../samples/javaee7angular/data/Person.java | 12 ++++-- .../resources/sql/create-mariadb-database.sql | 4 ++ src/main/resources/sql/create.sql | 3 +- src/main/resources/sql/drop.sql | 1 - src/main/resources/sql/load.sql | 42 +++++++++---------- 6 files changed, 53 insertions(+), 27 deletions(-) create mode 100644 nb-configuration.xml create mode 100644 src/main/resources/sql/create-mariadb-database.sql diff --git a/nb-configuration.xml b/nb-configuration.xml new file mode 100644 index 0000000..4da1f6c --- /dev/null +++ b/nb-configuration.xml @@ -0,0 +1,18 @@ + + + + + + ide + + diff --git a/src/main/java/com/cortez/samples/javaee7angular/data/Person.java b/src/main/java/com/cortez/samples/javaee7angular/data/Person.java index a88f350..c23a2a8 100644 --- a/src/main/java/com/cortez/samples/javaee7angular/data/Person.java +++ b/src/main/java/com/cortez/samples/javaee7angular/data/Person.java @@ -1,5 +1,6 @@ package com.cortez.samples.javaee7angular.data; +import java.io.Serializable; import javax.persistence.*; /** @@ -8,16 +9,21 @@ * @author Roberto Cortez */ @Entity -public class Person { +@Table(name = "PERSON") +public class Person implements Serializable { @Id - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id") - @SequenceGenerator(name = "id", sequenceName = "id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + //@GeneratedValue(strategy = GenerationType.SEQUENCE) + //@SequenceGenerator(name = "ID", sequenceName = "ID") private Long id; + @Column(name = "NAME") private String name; + @Column(name = "DESCRIPTION") private String description; + @Column(name = "IMAGEURL") private String imageUrl; public Long getId() { diff --git a/src/main/resources/sql/create-mariadb-database.sql b/src/main/resources/sql/create-mariadb-database.sql new file mode 100644 index 0000000..35fd86d --- /dev/null +++ b/src/main/resources/sql/create-mariadb-database.sql @@ -0,0 +1,4 @@ +create user emcs identified by 'emcs'; +create database emcsdb CHARACTER SET = utf8 COLLATE utf8_bin; +grant all privileges on emcsdb.* to 'emcs'@'localhost'; +flush privileges; diff --git a/src/main/resources/sql/create.sql b/src/main/resources/sql/create.sql index 1af9fe2..510dce6 100644 --- a/src/main/resources/sql/create.sql +++ b/src/main/resources/sql/create.sql @@ -1,2 +1 @@ -CREATE SEQUENCE ID START WITH 100 -CREATE TABLE PERSON("ID" INTEGER not null primary key, "NAME" VARCHAR(50), "DESCRIPTION" VARCHAR(100), "IMAGEURL" VARCHAR(500)) +CREATE TABLE PERSON (ID INT NOT NULL AUTO_INCREMENT, NAME VARCHAR(50), DESCRIPTION VARCHAR(100), IMAGEURL VARCHAR(500), PRIMARY KEY (ID) ); diff --git a/src/main/resources/sql/drop.sql b/src/main/resources/sql/drop.sql index c93f0ed..39c3015 100644 --- a/src/main/resources/sql/drop.sql +++ b/src/main/resources/sql/drop.sql @@ -1,2 +1 @@ DROP TABLE PERSON -DROP SEQUENCE ID diff --git a/src/main/resources/sql/load.sql b/src/main/resources/sql/load.sql index 6cda2cb..6f26f6d 100644 --- a/src/main/resources/sql/load.sql +++ b/src/main/resources/sql/load.sql @@ -1,21 +1,21 @@ -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (1, 'Uzumaki Naruto', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20140523045537/naruto/images/thumb/3/36/Naruto_Uzumaki.png/300px-Naruto_Uzumaki.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (2, 'Hatake Kakashi', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20140616090940/naruto/images/thumb/b/b3/KakashiHatake.png/300px-KakashiHatake.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (3, 'Haruno Sakura', 'Konoha', 'http://vignette2.wikia.nocookie.net/naruto/images/b/ba/Sakurap2.png/revision/latest/scale-to-width-down/300?cb=20150825101949') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (4, 'Uchiha Sasuke', 'Missing-nin', 'http://img1.wikia.nocookie.net/__cb20150110232732/naruto/images/c/c3/Sasuke_headshot.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (5, 'Gaara', 'Sunagakure', 'http://img3.wikia.nocookie.net/__cb20130910220958/naruto/images/thumb/0/0f/Gaara_Part_II.png/300px-Gaara_Part_II.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (6, 'Killer Bee', 'Kumogakure', 'http://vignette3.wikia.nocookie.net/naruto/images/6/63/Killer_B.png/revision/latest/scale-to-width-down/300?cb=20150917075056') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (7, 'Jiraya', 'Konoha', 'http://img2.wikia.nocookie.net/__cb20120925123905/naruto/images/thumb/2/21/Profile_Jiraiya.PNG/300px-Profile_Jiraiya.PNG') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (8, 'Namikaze Minato', 'Konoha', 'http://img4.wikia.nocookie.net/__cb20140209115534/naruto/images/thumb/1/1f/Minato_Namikaze.PNG/300px-Minato_Namikaze.PNG') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (9, 'Uchiha Madara', 'Missing-nin', 'http://img2.wikia.nocookie.net/__cb20140724225045/naruto/images/thumb/c/cf/Madara_newshot.png/300px-Madara_newshot.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (10, 'Senju Hashirama', 'Konoha', 'http://img2.wikia.nocookie.net/__cb20120915132454/naruto/images/thumb/7/7e/Hashirama_Senju.png/300px-Hashirama_Senju.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (11, 'Might Guy', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20150401084456/naruto/images/3/31/Might_Guy.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (12, 'Hyuga Neji', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20150123214015/naruto/images/6/63/Neji_Part_2.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (13, 'Rock Lee', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20131029112352/naruto/images/thumb/7/7d/Lee_timeskip.png/300px-Lee_timeskip.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (14, 'Uchiha Obito', 'Missing-nin', 'http://img1.wikia.nocookie.net/__cb20140616090247/naruto/images/thumb/a/a0/Obito_Uchiha2.png/300px-Obito_Uchiha2.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (15, 'Kurama', 'Tailed Beast', 'http://img1.wikia.nocookie.net/__cb20140818171718/naruto/images/thumb/7/7b/Kurama2.png/300px-Kurama2.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (16, 'Uzumaki Kushina', 'Konoha', 'http://img4.wikia.nocookie.net/__cb20121006054451/naruto/images/thumb/4/4d/Kushina_2.png/300px-Kushina_2.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (17, 'Nara Shikamaru', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20130917013425/naruto/images/thumb/9/9a/Shikamaru_Nara.png/300px-Shikamaru_Nara.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (18, 'Sarutobi Hiruzen', 'Konoha', 'http://img4.wikia.nocookie.net/__cb20120912121115/naruto/images/thumb/e/e4/Hiruzen_Sarutobi.png/300px-Hiruzen_Sarutobi.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (19, 'Tsunade', 'Konoha', 'http://img4.wikia.nocookie.net/__cb20150108211132/naruto/images/b/b3/Tsunade_infobox2.png') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (20, 'Orochimaru', 'Missing-nin', 'http://vignette2.wikia.nocookie.net/naruto/images/1/14/Orochimaru_Infobox.png/revision/latest/scale-to-width-down/300?cb=20150925223113') -INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (21, 'Uchicha Itachi', 'Missing-nin', 'http://vignette2.wikia.nocookie.net/naruto/images/b/bb/Itachi.png/revision/latest/scale-to-width-down/300?cb=20150602102445') +INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (1, 'Uzumaki Naruto', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20140523045537/naruto/images/thumb/3/36/Naruto_Uzumaki.png/300px-Naruto_Uzumaki.png') +INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (2, 'Hatake Kakashi', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20140616090940/naruto/images/thumb/b/b3/KakashiHatake.png/300px-KakashiHatake.png') +INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (3, 'Haruno Sakura', 'Konoha', 'http://vignette2.wikia.nocookie.net/naruto/images/b/ba/Sakurap2.png/revision/latest/scale-to-width-down/300?cb=20150825101949') +INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (4, 'Uchiha Sasuke', 'Missing-nin', 'http://img1.wikia.nocookie.net/__cb20150110232732/naruto/images/c/c3/Sasuke_headshot.png') +INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (5, 'Gaara', 'Sunagakure', 'http://img3.wikia.nocookie.net/__cb20130910220958/naruto/images/thumb/0/0f/Gaara_Part_II.png/300px-Gaara_Part_II.png') +INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (6, 'Killer Bee', 'Kumogakure', 'http://vignette3.wikia.nocookie.net/naruto/images/6/63/Killer_B.png/revision/latest/scale-to-width-down/300?cb=20150917075056') +INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (7, 'Jiraya', 'Konoha', 'http://img2.wikia.nocookie.net/__cb20120925123905/naruto/images/thumb/2/21/Profile_Jiraiya.PNG/300px-Profile_Jiraiya.PNG') +INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (8, 'Namikaze Minato', 'Konoha', 'http://img4.wikia.nocookie.net/__cb20140209115534/naruto/images/thumb/1/1f/Minato_Namikaze.PNG/300px-Minato_Namikaze.PNG') +INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (9, 'Uchiha Madara', 'Missing-nin', 'http://img2.wikia.nocookie.net/__cb20140724225045/naruto/images/thumb/c/cf/Madara_newshot.png/300px-Madara_newshot.png') +INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (10, 'Senju Hashirama', 'Konoha', 'http://img2.wikia.nocookie.net/__cb20120915132454/naruto/images/thumb/7/7e/Hashirama_Senju.png/300px-Hashirama_Senju.png') +INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (11, 'Might Guy', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20150401084456/naruto/images/3/31/Might_Guy.png') +INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (12, 'Hyuga Neji', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20150123214015/naruto/images/6/63/Neji_Part_2.png') +INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (13, 'Rock Lee', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20131029112352/naruto/images/thumb/7/7d/Lee_timeskip.png/300px-Lee_timeskip.png') +INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (14, 'Uchiha Obito', 'Missing-nin', 'http://img1.wikia.nocookie.net/__cb20140616090247/naruto/images/thumb/a/a0/Obito_Uchiha2.png/300px-Obito_Uchiha2.png') +INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (15, 'Kurama', 'Tailed Beast', 'http://img1.wikia.nocookie.net/__cb20140818171718/naruto/images/thumb/7/7b/Kurama2.png/300px-Kurama2.png') +INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (16, 'Uzumaki Kushina', 'Konoha', 'http://img4.wikia.nocookie.net/__cb20121006054451/naruto/images/thumb/4/4d/Kushina_2.png/300px-Kushina_2.png') +INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (17, 'Nara Shikamaru', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20130917013425/naruto/images/thumb/9/9a/Shikamaru_Nara.png/300px-Shikamaru_Nara.png') +INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (18, 'Sarutobi Hiruzen', 'Konoha', 'http://img4.wikia.nocookie.net/__cb20120912121115/naruto/images/thumb/e/e4/Hiruzen_Sarutobi.png/300px-Hiruzen_Sarutobi.png') +INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (19, 'Tsunade', 'Konoha', 'http://img4.wikia.nocookie.net/__cb20150108211132/naruto/images/b/b3/Tsunade_infobox2.png') +INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (20, 'Orochimaru', 'Missing-nin', 'http://vignette2.wikia.nocookie.net/naruto/images/1/14/Orochimaru_Infobox.png/revision/latest/scale-to-width-down/300?cb=20150925223113') +INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (21, 'Uchicha Itachi', 'Missing-nin', 'http://vignette2.wikia.nocookie.net/naruto/images/b/bb/Itachi.png/revision/latest/scale-to-width-down/300?cb=20150602102445') From 47dfc50a666c5065a17562ad298b3dc86aca7168 Mon Sep 17 00:00:00 2001 From: Arkadios Tsamourliadis Date: Wed, 11 May 2016 18:26:21 +0300 Subject: [PATCH 3/8] Person => Issue transformation --- pom.xml | 12 ++++ .../data/{Person.java => Issue.java} | 40 +++++------ .../pagination/PaginatedListWrapper.java | 6 +- ...PersonResource.java => IssueResource.java} | 58 +++++++-------- src/main/resources/sql/create.sql | 2 +- src/main/resources/sql/drop.sql | 2 +- src/main/resources/sql/load.sql | 36 ++++------ src/main/webapp/index.html | 66 ++++++++--------- .../webapp/script/{person.js => issue.js} | 70 +++++++++---------- 9 files changed, 145 insertions(+), 147 deletions(-) rename src/main/java/com/cortez/samples/javaee7angular/data/{Person.java => Issue.java} (51%) rename src/main/java/com/cortez/samples/javaee7angular/rest/{PersonResource.java => IssueResource.java} (58%) rename src/main/webapp/script/{person.js => issue.js} (67%) diff --git a/pom.xml b/pom.xml index ae635db..c22360e 100644 --- a/pom.xml +++ b/pom.xml @@ -111,6 +111,18 @@ javaee-api ${version.dependency.javaee} provided + + + com.sun.mail + javax.mail + + + + + + hsqldb + hsqldb + 1.8.0.10 diff --git a/src/main/java/com/cortez/samples/javaee7angular/data/Person.java b/src/main/java/com/cortez/samples/javaee7angular/data/Issue.java similarity index 51% rename from src/main/java/com/cortez/samples/javaee7angular/data/Person.java rename to src/main/java/com/cortez/samples/javaee7angular/data/Issue.java index c23a2a8..74733b0 100644 --- a/src/main/java/com/cortez/samples/javaee7angular/data/Person.java +++ b/src/main/java/com/cortez/samples/javaee7angular/data/Issue.java @@ -1,6 +1,7 @@ package com.cortez.samples.javaee7angular.data; import java.io.Serializable; +import java.math.BigDecimal; import javax.persistence.*; /** @@ -9,8 +10,8 @@ * @author Roberto Cortez */ @Entity -@Table(name = "PERSON") -public class Person implements Serializable { +@Table(name = "ISSUE") +public class Issue implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) //@GeneratedValue(strategy = GenerationType.SEQUENCE) @@ -20,11 +21,11 @@ public class Person implements Serializable { @Column(name = "NAME") private String name; - @Column(name = "DESCRIPTION") - private String description; + @Column(name = "P1RATE", precision = 7, scale = 5) + private BigDecimal p1Rate; - @Column(name = "IMAGEURL") - private String imageUrl; + @Column(name = "P2RATE", precision = 7, scale = 5) + private BigDecimal p2Rate; public Long getId() { return id; @@ -42,31 +43,22 @@ public void setName(String name) { this.name = name; } - public String getDescription() { - return description; + public BigDecimal getP1Rate() { + return p1Rate; } - public void setDescription(String description) { - this.description = description; + public BigDecimal getP2Rate() { + return p2Rate; } - public String getImageUrl() { - return imageUrl; + public void setP1Rate(BigDecimal p1Rate) { + this.p1Rate = p1Rate; } - public void setImageUrl(String link) { - this.imageUrl = link; - } - - @Override - public boolean equals(Object o) { - if (this == o) { return true; } - if (o == null || getClass() != o.getClass()) { return false; } - - Person person = (Person) o; - - return id.equals(person.id); + public void setP2Rate(BigDecimal p2Rate) { + this.p2Rate = p2Rate; } + @Override public int hashCode() { diff --git a/src/main/java/com/cortez/samples/javaee7angular/pagination/PaginatedListWrapper.java b/src/main/java/com/cortez/samples/javaee7angular/pagination/PaginatedListWrapper.java index a86f92d..68baa93 100644 --- a/src/main/java/com/cortez/samples/javaee7angular/pagination/PaginatedListWrapper.java +++ b/src/main/java/com/cortez/samples/javaee7angular/pagination/PaginatedListWrapper.java @@ -1,6 +1,6 @@ package com.cortez.samples.javaee7angular.pagination; -import com.cortez.samples.javaee7angular.data.Person; +import com.cortez.samples.javaee7angular.data.Issue; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @@ -21,7 +21,7 @@ public class PaginatedListWrapper implements Serializable { private String sortFields; private String sortDirections; @XmlElement - private List list; + private List list; public Integer getCurrentPage() { return currentPage; @@ -67,7 +67,7 @@ public List getList() { return list; } - public void setList(List list) { + public void setList(List list) { this.list = list; } } diff --git a/src/main/java/com/cortez/samples/javaee7angular/rest/PersonResource.java b/src/main/java/com/cortez/samples/javaee7angular/rest/IssueResource.java similarity index 58% rename from src/main/java/com/cortez/samples/javaee7angular/rest/PersonResource.java rename to src/main/java/com/cortez/samples/javaee7angular/rest/IssueResource.java index 7af10e9..cd83e33 100644 --- a/src/main/java/com/cortez/samples/javaee7angular/rest/PersonResource.java +++ b/src/main/java/com/cortez/samples/javaee7angular/rest/IssueResource.java @@ -1,6 +1,6 @@ package com.cortez.samples.javaee7angular.rest; -import com.cortez.samples.javaee7angular.data.Person; +import com.cortez.samples.javaee7angular.data.Issue; import com.cortez.samples.javaee7angular.pagination.PaginatedListWrapper; import javax.ejb.Stateless; @@ -19,31 +19,31 @@ */ @Stateless @ApplicationPath("/resources") -@Path("persons") +@Path("issues") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) -public class PersonResource extends Application { +public class IssueResource extends Application { @PersistenceContext private EntityManager entityManager; - private Integer countPersons() { - Query query = entityManager.createQuery("SELECT COUNT(p.id) FROM Person p"); + private Integer countIssues() { + Query query = entityManager.createQuery("SELECT COUNT(p.id) FROM Issue p"); return ((Long) query.getSingleResult()).intValue(); } @SuppressWarnings("unchecked") - private List findPersons(int startPosition, int maxResults, String sortFields, String sortDirections) { + private List findIssue(int startPosition, int maxResults, String sortFields, String sortDirections) { Query query = - entityManager.createQuery("SELECT p FROM Person p ORDER BY p." + sortFields + " " + sortDirections); + entityManager.createQuery("SELECT p FROM Issue p ORDER BY p." + sortFields + " " + sortDirections); query.setFirstResult(startPosition); query.setMaxResults(maxResults); return query.getResultList(); } - private PaginatedListWrapper findPersons(PaginatedListWrapper wrapper) { - wrapper.setTotalResults(countPersons()); + private PaginatedListWrapper findIssues(PaginatedListWrapper wrapper) { + wrapper.setTotalResults(countIssues()); int start = (wrapper.getCurrentPage() - 1) * wrapper.getPageSize(); - wrapper.setList(findPersons(start, + wrapper.setList(findIssue(start, wrapper.getPageSize(), wrapper.getSortFields(), wrapper.getSortDirections())); @@ -52,7 +52,7 @@ private PaginatedListWrapper findPersons(PaginatedListWrapper wrapper) { @GET @Produces(MediaType.APPLICATION_JSON) - public PaginatedListWrapper listPersons(@DefaultValue("1") + public PaginatedListWrapper listIssues(@DefaultValue("1") @QueryParam("page") Integer page, @DefaultValue("id") @@ -66,37 +66,37 @@ public PaginatedListWrapper listPersons(@DefaultValue("1") paginatedListWrapper.setSortFields(sortFields); paginatedListWrapper.setSortDirections(sortDirections); paginatedListWrapper.setPageSize(10); - return findPersons(paginatedListWrapper); + return findIssues(paginatedListWrapper); } @GET @Path("{id}") - public Person getPerson(@PathParam("id") Long id) { - return entityManager.find(Person.class, id); + public Issue getIssue(@PathParam("id") Long id) { + return entityManager.find(Issue.class, id); } @POST - public Person savePerson(Person person) { - if (person.getId() == null) { - Person personToSave = new Person(); - personToSave.setName(person.getName()); - personToSave.setDescription(person.getDescription()); - personToSave.setImageUrl(person.getImageUrl()); - entityManager.persist(person); + public Issue saveIssue(Issue issue) { + if (issue.getId() == null) { + Issue issueToSave = new Issue(); + issueToSave.setName(issue.getName()); + issueToSave.setP1Rate(issue.getP1Rate()); + issueToSave.setP2Rate(issue.getP2Rate()); + entityManager.persist(issue); } else { - Person personToUpdate = getPerson(person.getId()); - personToUpdate.setName(person.getName()); - personToUpdate.setDescription(person.getDescription()); - personToUpdate.setImageUrl(person.getImageUrl()); - person = entityManager.merge(personToUpdate); + Issue issueToUpdate = getIssue(issue.getId()); + issueToUpdate.setName(issue.getName()); + issueToUpdate.setP1Rate(issue.getP1Rate()); + issueToUpdate.setP2Rate(issue.getP2Rate()); + issue = entityManager.merge(issueToUpdate); } - return person; + return issue; } @DELETE @Path("{id}") - public void deletePerson(@PathParam("id") Long id) { - entityManager.remove(getPerson(id)); + public void deleteIssue(@PathParam("id") Long id) { + entityManager.remove(getIssue(id)); } } diff --git a/src/main/resources/sql/create.sql b/src/main/resources/sql/create.sql index 510dce6..0439e0a 100644 --- a/src/main/resources/sql/create.sql +++ b/src/main/resources/sql/create.sql @@ -1 +1 @@ -CREATE TABLE PERSON (ID INT NOT NULL AUTO_INCREMENT, NAME VARCHAR(50), DESCRIPTION VARCHAR(100), IMAGEURL VARCHAR(500), PRIMARY KEY (ID) ); +CREATE TABLE ISSUE (ID INT NOT NULL AUTO_INCREMENT, NAME VARCHAR(50), P1RATE DECIMAL(7.5), P1RATE DECIMAL(7.5), PRIMARY KEY (ID) ); diff --git a/src/main/resources/sql/drop.sql b/src/main/resources/sql/drop.sql index 39c3015..4dfd8b4 100644 --- a/src/main/resources/sql/drop.sql +++ b/src/main/resources/sql/drop.sql @@ -1 +1 @@ -DROP TABLE PERSON +DROP TABLE ISSUE diff --git a/src/main/resources/sql/load.sql b/src/main/resources/sql/load.sql index 6f26f6d..fd9cc82 100644 --- a/src/main/resources/sql/load.sql +++ b/src/main/resources/sql/load.sql @@ -1,21 +1,15 @@ -INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (1, 'Uzumaki Naruto', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20140523045537/naruto/images/thumb/3/36/Naruto_Uzumaki.png/300px-Naruto_Uzumaki.png') -INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (2, 'Hatake Kakashi', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20140616090940/naruto/images/thumb/b/b3/KakashiHatake.png/300px-KakashiHatake.png') -INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (3, 'Haruno Sakura', 'Konoha', 'http://vignette2.wikia.nocookie.net/naruto/images/b/ba/Sakurap2.png/revision/latest/scale-to-width-down/300?cb=20150825101949') -INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (4, 'Uchiha Sasuke', 'Missing-nin', 'http://img1.wikia.nocookie.net/__cb20150110232732/naruto/images/c/c3/Sasuke_headshot.png') -INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (5, 'Gaara', 'Sunagakure', 'http://img3.wikia.nocookie.net/__cb20130910220958/naruto/images/thumb/0/0f/Gaara_Part_II.png/300px-Gaara_Part_II.png') -INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (6, 'Killer Bee', 'Kumogakure', 'http://vignette3.wikia.nocookie.net/naruto/images/6/63/Killer_B.png/revision/latest/scale-to-width-down/300?cb=20150917075056') -INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (7, 'Jiraya', 'Konoha', 'http://img2.wikia.nocookie.net/__cb20120925123905/naruto/images/thumb/2/21/Profile_Jiraiya.PNG/300px-Profile_Jiraiya.PNG') -INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (8, 'Namikaze Minato', 'Konoha', 'http://img4.wikia.nocookie.net/__cb20140209115534/naruto/images/thumb/1/1f/Minato_Namikaze.PNG/300px-Minato_Namikaze.PNG') -INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (9, 'Uchiha Madara', 'Missing-nin', 'http://img2.wikia.nocookie.net/__cb20140724225045/naruto/images/thumb/c/cf/Madara_newshot.png/300px-Madara_newshot.png') -INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (10, 'Senju Hashirama', 'Konoha', 'http://img2.wikia.nocookie.net/__cb20120915132454/naruto/images/thumb/7/7e/Hashirama_Senju.png/300px-Hashirama_Senju.png') -INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (11, 'Might Guy', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20150401084456/naruto/images/3/31/Might_Guy.png') -INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (12, 'Hyuga Neji', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20150123214015/naruto/images/6/63/Neji_Part_2.png') -INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (13, 'Rock Lee', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20131029112352/naruto/images/thumb/7/7d/Lee_timeskip.png/300px-Lee_timeskip.png') -INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (14, 'Uchiha Obito', 'Missing-nin', 'http://img1.wikia.nocookie.net/__cb20140616090247/naruto/images/thumb/a/a0/Obito_Uchiha2.png/300px-Obito_Uchiha2.png') -INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (15, 'Kurama', 'Tailed Beast', 'http://img1.wikia.nocookie.net/__cb20140818171718/naruto/images/thumb/7/7b/Kurama2.png/300px-Kurama2.png') -INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (16, 'Uzumaki Kushina', 'Konoha', 'http://img4.wikia.nocookie.net/__cb20121006054451/naruto/images/thumb/4/4d/Kushina_2.png/300px-Kushina_2.png') -INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (17, 'Nara Shikamaru', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20130917013425/naruto/images/thumb/9/9a/Shikamaru_Nara.png/300px-Shikamaru_Nara.png') -INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (18, 'Sarutobi Hiruzen', 'Konoha', 'http://img4.wikia.nocookie.net/__cb20120912121115/naruto/images/thumb/e/e4/Hiruzen_Sarutobi.png/300px-Hiruzen_Sarutobi.png') -INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (19, 'Tsunade', 'Konoha', 'http://img4.wikia.nocookie.net/__cb20150108211132/naruto/images/b/b3/Tsunade_infobox2.png') -INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (20, 'Orochimaru', 'Missing-nin', 'http://vignette2.wikia.nocookie.net/naruto/images/1/14/Orochimaru_Infobox.png/revision/latest/scale-to-width-down/300?cb=20150925223113') -INSERT INTO PERSON(ID, NAME, DESCRIPTION, IMAGEURL) VALUES (21, 'Uchicha Itachi', 'Missing-nin', 'http://vignette2.wikia.nocookie.net/naruto/images/b/bb/Itachi.png/revision/latest/scale-to-width-down/300?cb=20150602102445') +INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (1, 'Uzumaki Naruto', 3.4, 5.4) +INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (2, 'Hatake Kakashi', 3.4, 5.4) +INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (3, 'Haruno Sakura', 3.4, 5.4) +INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (4, 'Uchiha Sasuke', 3.4, 5.4) +INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (5, 'Gaara', 3.4, 5.4) +INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (6, 'Killer Bee', 3.4, 5.4) +INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (7, 'Jiraya', 3.4, 5.4) +INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (8, 'Namikaze Minato', 3.2, 3.4) +INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (9, 'Uchiha Madara', 3.2, 3.4) +INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (10, 'Senju Hashirama', 3.2, 3.4) +INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (11, 'Might Guy', 3.2, 3.4) +INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (12, 'Hyuga Neji', 3.2, 3.4) +INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (13, 'Rock Lee', 3.2, 3.4) +INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (14, 'Uchiha Obito', 3.2, 3.4) +INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (15, 'Kurama', 3.2, 3.4) \ No newline at end of file diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html index a5bbca0..ca824ec 100644 --- a/src/main/webapp/index.html +++ b/src/main/webapp/index.html @@ -1,6 +1,6 @@ - + javaee7-angular @@ -26,7 +26,7 @@ - + @@ -44,9 +44,9 @@

Java EE - Angular Application


-
+
-

List Persons

+

List Issues

@@ -54,81 +54,81 @@

List Persons

+ total-items="issues.totalResults" items-per-page="issues.pageSize" + ng-model="issues.currentPage" ng-change="refreshGrid()">
-
- -
-

Add Person

+
+ +
+

Add issue

-
-

Edit Person

+
+

Edit issue

-
+ -
+
- + -

Add Name.

-

Name must be at least 2 characters long.

-

Name cannot be longer than 50 characters.

+

Add Name.

+

Name must be at least 2 characters long.

+

Name cannot be longer than 50 characters.

-
+
- + -

Add Description.

-

Description must be at least 5 characters long.

-

Description cannot be longer than 100 characters.

+

Add Description.

+

Description must be at least 5 characters long.

+

Description cannot be longer than 100 characters.

-
+
- + -

Add Image URL.

-

Invalid Image URL.

+

Add Image URL.

+

Invalid Image URL.

-
- +
+
- +
diff --git a/src/main/webapp/script/person.js b/src/main/webapp/script/issue.js similarity index 67% rename from src/main/webapp/script/person.js rename to src/main/webapp/script/issue.js index 58ecbaa..baeba6f 100644 --- a/src/main/webapp/script/person.js +++ b/src/main/webapp/script/issue.js @@ -1,20 +1,20 @@ -var app = angular.module('persons', ['ngResource', 'ngGrid', 'ui.bootstrap']); +var app = angular.module('issues', ['ngResource', 'ngGrid', 'ui.bootstrap']); -// Create a controller with name personsListController to bind to the grid section. -app.controller('personsListController', function ($scope, $rootScope, personService) { +// Create a controller with name issuesListController to bind to the grid section. +app.controller('issuesListController', function ($scope, $rootScope, issueService) { // Initialize required information: sorting, the first page to show and the grid options. $scope.sortInfo = {fields: ['id'], directions: ['asc']}; - $scope.persons = {currentPage: 1}; + $scope.issues = {currentPage: 1}; $scope.gridOptions = { - data: 'persons.list', + data: 'issues.list', useExternalSorting: true, sortInfo: $scope.sortInfo, columnDefs: [ { field: 'id', displayName: 'Id' }, - { field: 'name', displayName: 'Name' }, - { field: 'description', displayName: 'Description' }, + { field: 'p1Rate', displayName: 'p1Rate' }, + { field: 'p2Rate', displayName: 'p2Rate' }, { field: '', width: 30, cellTemplate: '' } ], @@ -23,33 +23,33 @@ app.controller('personsListController', function ($scope, $rootScope, personServ // Broadcasts an event when a row is selected, to signal the form that it needs to load the row data. afterSelectionChange: function (rowItem) { if (rowItem.selected) { - $rootScope.$broadcast('personSelected', $scope.gridOptions.selectedItems[0].id); + $rootScope.$broadcast('issueSelected', $scope.gridOptions.selectedItems[0].id); } } }; // Refresh the grid, calling the appropriate rest method. $scope.refreshGrid = function () { - var listPersonsArgs = { - page: $scope.persons.currentPage, + var listIssuesArgs = { + page: $scope.issues.currentPage, sortFields: $scope.sortInfo.fields[0], sortDirections: $scope.sortInfo.directions[0] }; - personService.get(listPersonsArgs, function (data) { - $scope.persons = data; + issueService.get(listIssuesArgs, function (data) { + $scope.issues = data; }) }; // Broadcast an event when an element in the grid is deleted. No real deletion is perfomed at this point. $scope.deleteRow = function (row) { - $rootScope.$broadcast('deletePerson', row.entity.id); + $rootScope.$broadcast('deleteIssue', row.entity.id); }; // Watch the sortInfo variable. If changes are detected than we need to refresh the grid. // This also works for the first page access, since we assign the initial sorting in the initialize section. $scope.$watch('sortInfo', function () { - $scope.persons = {currentPage: 1}; + $scope.issues = {currentPage: 1}; $scope.refreshGrid(); }, true); @@ -60,7 +60,7 @@ app.controller('personsListController', function ($scope, $rootScope, personServ $scope.sortInfo = sortInfo; }); - // Picks the event broadcasted when a person is saved or deleted to refresh the grid elements with the most + // Picks the event broadcasted when a issue is saved or deleted to refresh the grid elements with the most // updated information. $scope.$on('refreshGrid', function () { $scope.refreshGrid(); @@ -72,28 +72,28 @@ app.controller('personsListController', function ($scope, $rootScope, personServ }); }); -// Create a controller with name personsFormController to bind to the form section. -app.controller('personsFormController', function ($scope, $rootScope, personService) { +// Create a controller with name issuesFormController to bind to the form section. +app.controller('issuesFormController', function ($scope, $rootScope, issueService) { // Clears the form. Either by clicking the 'Clear' button in the form, or when a successfull save is performed. $scope.clearForm = function () { - $scope.person = null; + $scope.issue = null; // For some reason, I was unable to clear field values with type 'url' if the value is invalid. // This is a workaroud. Needs proper investigation. document.getElementById('imageUrl').value = null; // Resets the form validation state. - $scope.personForm.$setPristine(); + $scope.issueForm.$setPristine(); // Broadcast the event to also clear the grid selection. $rootScope.$broadcast('clear'); }; - // Calls the rest method to save a person. - $scope.updatePerson = function () { - personService.save($scope.person).$promise.then( + // Calls the rest method to save a issue. + $scope.updateIssue = function () { + issueService.save($scope.issue).$promise.then( function () { // Broadcast the event to refresh the grid. $rootScope.$broadcast('refreshGrid'); // Broadcast the event to display a save message. - $rootScope.$broadcast('personSaved'); + $rootScope.$broadcast('issueSaved'); $scope.clearForm(); }, function () { @@ -102,21 +102,21 @@ app.controller('personsFormController', function ($scope, $rootScope, personServ }); }; - // Picks up the event broadcasted when the person is selected from the grid and perform the person load by calling + // Picks up the event broadcasted when the issue is selected from the grid and perform the issue load by calling // the appropiate rest service. - $scope.$on('personSelected', function (event, id) { - $scope.person = personService.get({id: id}); + $scope.$on('issueSelected', function (event, id) { + $scope.issue = issueService.get({id: id}); }); - // Picks us the event broadcasted when the person is deleted from the grid and perform the actual person delete by + // Picks us the event broadcasted when the issue is deleted from the grid and perform the actual issue delete by // calling the appropiate rest service. - $scope.$on('deletePerson', function (event, id) { - personService.delete({id: id}).$promise.then( + $scope.$on('deleteIssue', function (event, id) { + issueService.delete({id: id}).$promise.then( function () { // Broadcast the event to refresh the grid. $rootScope.$broadcast('refreshGrid'); // Broadcast the event to display a delete message. - $rootScope.$broadcast('personDeleted'); + $rootScope.$broadcast('issueDeleted'); $scope.clearForm(); }, function () { @@ -129,14 +129,14 @@ app.controller('personsFormController', function ($scope, $rootScope, personServ // Create a controller with name alertMessagesController to bind to the feedback messages section. app.controller('alertMessagesController', function ($scope) { // Picks up the event to display a saved message. - $scope.$on('personSaved', function () { + $scope.$on('issueSaved', function () { $scope.alerts = [ { type: 'success', msg: 'Record saved successfully!' } ]; }); // Picks up the event to display a deleted message. - $scope.$on('personDeleted', function () { + $scope.$on('issueDeleted', function () { $scope.alerts = [ { type: 'success', msg: 'Record deleted successfully!' } ]; @@ -154,7 +154,7 @@ app.controller('alertMessagesController', function ($scope) { }; }); -// Service that provides persons operations -app.factory('personService', function ($resource) { - return $resource('resources/persons/:id'); +// Service that provides issues operations +app.factory('issueService', function ($resource) { + return $resource('resources/issues/:id'); }); From c2956675aa323b96618ed7fe7eae685a90e43ade Mon Sep 17 00:00:00 2001 From: Arkadios Tsamourliadis Date: Thu, 12 May 2016 18:53:19 +0300 Subject: [PATCH 4/8] enables issue editing --- .../samples/javaee7angular/data/Issue.java | 12 ++--- .../javaee7angular/rest/IssueResource.java | 4 +- src/main/resources/sql/create.sql | 2 +- src/main/resources/sql/load.sql | 30 +++++------ src/main/webapp/index.html | 50 +++++++++---------- src/main/webapp/script/issue.js | 5 +- 6 files changed, 52 insertions(+), 51 deletions(-) diff --git a/src/main/java/com/cortez/samples/javaee7angular/data/Issue.java b/src/main/java/com/cortez/samples/javaee7angular/data/Issue.java index 74733b0..96f742c 100644 --- a/src/main/java/com/cortez/samples/javaee7angular/data/Issue.java +++ b/src/main/java/com/cortez/samples/javaee7angular/data/Issue.java @@ -18,8 +18,8 @@ public class Issue implements Serializable { //@SequenceGenerator(name = "ID", sequenceName = "ID") private Long id; - @Column(name = "NAME") - private String name; + @Column(name = "ISSUENUM") + private String issueNum; @Column(name = "P1RATE", precision = 7, scale = 5) private BigDecimal p1Rate; @@ -35,12 +35,12 @@ public void setId(Long id) { this.id = id; } - public String getName() { - return name; + public String getIssueNum() { + return issueNum; } - public void setName(String name) { - this.name = name; + public void setIssueNum(String issueNum) { + this.issueNum = issueNum; } public BigDecimal getP1Rate() { diff --git a/src/main/java/com/cortez/samples/javaee7angular/rest/IssueResource.java b/src/main/java/com/cortez/samples/javaee7angular/rest/IssueResource.java index cd83e33..7a06dbe 100644 --- a/src/main/java/com/cortez/samples/javaee7angular/rest/IssueResource.java +++ b/src/main/java/com/cortez/samples/javaee7angular/rest/IssueResource.java @@ -79,13 +79,13 @@ public Issue getIssue(@PathParam("id") Long id) { public Issue saveIssue(Issue issue) { if (issue.getId() == null) { Issue issueToSave = new Issue(); - issueToSave.setName(issue.getName()); + issueToSave.setIssueNum(issue.getIssueNum()); issueToSave.setP1Rate(issue.getP1Rate()); issueToSave.setP2Rate(issue.getP2Rate()); entityManager.persist(issue); } else { Issue issueToUpdate = getIssue(issue.getId()); - issueToUpdate.setName(issue.getName()); + issueToUpdate.setIssueNum(issue.getIssueNum()); issueToUpdate.setP1Rate(issue.getP1Rate()); issueToUpdate.setP2Rate(issue.getP2Rate()); issue = entityManager.merge(issueToUpdate); diff --git a/src/main/resources/sql/create.sql b/src/main/resources/sql/create.sql index 0439e0a..587adf9 100644 --- a/src/main/resources/sql/create.sql +++ b/src/main/resources/sql/create.sql @@ -1 +1 @@ -CREATE TABLE ISSUE (ID INT NOT NULL AUTO_INCREMENT, NAME VARCHAR(50), P1RATE DECIMAL(7.5), P1RATE DECIMAL(7.5), PRIMARY KEY (ID) ); +CREATE TABLE ISSUE (ID INT NOT NULL AUTO_INCREMENT, ISSUENUM VARCHAR(50), P1RATE DECIMAL(7.5), P2RATE DECIMAL(7.5), PRIMARY KEY (ID) ); diff --git a/src/main/resources/sql/load.sql b/src/main/resources/sql/load.sql index fd9cc82..b189d1f 100644 --- a/src/main/resources/sql/load.sql +++ b/src/main/resources/sql/load.sql @@ -1,15 +1,15 @@ -INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (1, 'Uzumaki Naruto', 3.4, 5.4) -INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (2, 'Hatake Kakashi', 3.4, 5.4) -INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (3, 'Haruno Sakura', 3.4, 5.4) -INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (4, 'Uchiha Sasuke', 3.4, 5.4) -INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (5, 'Gaara', 3.4, 5.4) -INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (6, 'Killer Bee', 3.4, 5.4) -INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (7, 'Jiraya', 3.4, 5.4) -INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (8, 'Namikaze Minato', 3.2, 3.4) -INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (9, 'Uchiha Madara', 3.2, 3.4) -INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (10, 'Senju Hashirama', 3.2, 3.4) -INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (11, 'Might Guy', 3.2, 3.4) -INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (12, 'Hyuga Neji', 3.2, 3.4) -INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (13, 'Rock Lee', 3.2, 3.4) -INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (14, 'Uchiha Obito', 3.2, 3.4) -INSERT INTO ISSUE(ID, NAME, P1RATE, P2RATE) VALUES (15, 'Kurama', 3.2, 3.4) \ No newline at end of file +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (1, 'Uzumaki Naruto', 3.4, 5.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (2, 'Hatake Kakashi', 3.4, 5.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (3, 'Haruno Sakura', 3.4, 5.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (4, 'Uchiha Sasuke', 3.4, 5.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (5, 'Gaara', 3.4, 5.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (6, 'Killer Bee', 3.4, 5.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (7, 'Jiraya', 3.4, 5.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (8, 'Namikaze Minato', 3.2, 3.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (9, 'Uchiha Madara', 3.2, 3.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (10, 'Senju Hashirama', 3.2, 3.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (11, 'Might Guy', 3.2, 3.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (12, 'Hyuga Neji', 3.2, 3.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (13, 'Rock Lee', 3.2, 3.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (14, 'Uchiha Obito', 3.2, 3.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (15, 'Kurama', 3.2, 3.4) \ No newline at end of file diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html index ca824ec..4cc9be9 100644 --- a/src/main/webapp/index.html +++ b/src/main/webapp/index.html @@ -75,55 +75,55 @@

Edit issue

-
- +
+ - + - -

Add Name.

-

Name must be at least 2 characters long.

-

Name cannot be longer than 50 characters.

+

Add Name.

+

Name must be at least 2 characters long.

+

Name cannot be longer than 50 characters.

- + - + -

Add Description.

-

Description must be at least 5 characters long.

-

Description cannot be longer than 100 characters.

+

Add Description.

+

Description must be at least 1 characters long.

+

Description cannot be longer than 100 characters.

-
- +
+ - + - -

Add Image URL.

-

Invalid Image URL.

+

Add Image URL.

+

Invalid Image URL.

-
- -
+
diff --git a/src/main/webapp/script/issue.js b/src/main/webapp/script/issue.js index baeba6f..49d7c80 100644 --- a/src/main/webapp/script/issue.js +++ b/src/main/webapp/script/issue.js @@ -13,8 +13,9 @@ app.controller('issuesListController', function ($scope, $rootScope, issueServic columnDefs: [ { field: 'id', displayName: 'Id' }, - { field: 'p1Rate', displayName: 'p1Rate' }, - { field: 'p2Rate', displayName: 'p2Rate' }, + { field: 'issueNum', displayName: 'Issue Number' }, + { field: 'p1Rate', displayName: 'Party 1 Rate' }, + { field: 'p2Rate', displayName: 'Party 2 Rate' }, { field: '', width: 30, cellTemplate: '' } ], From edf05fd2474548cdc14a07cbf579043174954aa7 Mon Sep 17 00:00:00 2001 From: Arkadios Tsamourliadis Date: Fri, 13 May 2016 18:33:15 +0300 Subject: [PATCH 5/8] added Negotiation EJB --- .../samples/javaee7angular/data/Issue.java | 22 ++++ .../negotiation/Negotiation.java | 114 ++++++++++++++++++ .../javaee7angular/rest/IssueResource.java | 2 + src/main/resources/sql/create.sql | 2 +- src/main/resources/sql/load.sql | 30 ++--- src/main/webapp/index.html | 28 ++--- src/main/webapp/script/issue.js | 13 +- 7 files changed, 177 insertions(+), 34 deletions(-) create mode 100644 src/main/java/com/cortez/samples/javaee7angular/negotiation/Negotiation.java diff --git a/src/main/java/com/cortez/samples/javaee7angular/data/Issue.java b/src/main/java/com/cortez/samples/javaee7angular/data/Issue.java index 96f742c..6861ee9 100644 --- a/src/main/java/com/cortez/samples/javaee7angular/data/Issue.java +++ b/src/main/java/com/cortez/samples/javaee7angular/data/Issue.java @@ -11,6 +11,8 @@ */ @Entity @Table(name = "ISSUE") +@NamedQueries({ + @NamedQuery(name = "Issue.findAll", query = "SELECT m FROM Issue m")}) public class Issue implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -26,6 +28,17 @@ public class Issue implements Serializable { @Column(name = "P2RATE", precision = 7, scale = 5) private BigDecimal p2Rate; + + @Column(name = "BELONGS", columnDefinition="smallint(1) default '0'") + private short belongs; + + public short getBelongs() { + return belongs; + } + + public void setBelongs(short belongs) { + this.belongs = belongs; + } public Long getId() { return id; @@ -59,6 +72,15 @@ public void setP2Rate(BigDecimal p2Rate) { this.p2Rate = p2Rate; } + public double getMrkDiff() { + if( p1Rate.doubleValue()>p2Rate.doubleValue() ) return p1Rate.doubleValue()-p2Rate.doubleValue(); + else return p2Rate.doubleValue()-p1Rate.doubleValue(); + } + + public void setWinningParty() { + if( p1Rate.doubleValue()>p2Rate.doubleValue() ) belongs=1; + else belongs=2; + } @Override public int hashCode() { diff --git a/src/main/java/com/cortez/samples/javaee7angular/negotiation/Negotiation.java b/src/main/java/com/cortez/samples/javaee7angular/negotiation/Negotiation.java new file mode 100644 index 0000000..35b75c4 --- /dev/null +++ b/src/main/java/com/cortez/samples/javaee7angular/negotiation/Negotiation.java @@ -0,0 +1,114 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.cortez.samples.javaee7angular.negotiation; + +import com.cortez.samples.javaee7angular.data.Issue; +import java.math.BigDecimal; +import java.util.List; +import javax.ejb.LocalBean; +import javax.ejb.Stateless; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; + +/** + * + * @author Arkadios.Tsamourliadis + */ +@Stateless +@LocalBean +public class Negotiation { + + + @PersistenceContext(unitName = "myPU") + private EntityManager em; + + + public List getAllIssues() { + Query query = em.createNamedQuery("Issue.findAll"); + List results = query.getResultList(); + return results; + } + + private void normalizeRates(Issue issue, double p1sum, double p2sum){ + issue.setP1Rate(new BigDecimal(100.0*issue.getP1Rate().doubleValue()/p1sum)); + issue.setP2Rate(new BigDecimal(100.0*issue.getP2Rate().doubleValue()/p2sum)); + } + + private String CalculateNormRates(List issues) { + //ofstream outResultFile( "result.txt", ios::app ); + double p1sum=0; + double p2sum=0; + String calcTextBox=""; + + for (Issue issue : issues) { + p1sum += issue.getP1Rate().doubleValue(); + p2sum += issue.getP2Rate().doubleValue(); + /////////////////////////// + calcTextBox=calcTextBox+"Calculating SumS p1, p2: "+p1sum+", "+p2sum+"\r\n"; + calcTextBox=calcTextBox+" Issue name: "+issue.getIssueNum()+" rates: "+issue.getP1Rate()+" "+issue.getP2Rate()+"\r\n"; + } + //cout<<"\nSum of Party 1 Rates:"< issues) { + //ofstream outResultFile( "result.txt", ios::app ); + + //At each iteration an Issue will be Resolved + for (int genIndex=0; genIndex < issues.size(); genIndex++) + { + double maxDiff=0; + int maxDiffIssueIndex=-1; + + //Find an Issue to Resolve + for (int i=0; i= maxDiff ) { + maxDiff = issues.get(i).getMrkDiff(); + maxDiffIssueIndex = i; + } + } + issues.get(maxDiffIssueIndex).setWinningParty(); //This Issue has just been resolved + + + String tmptextbox=""; + tmptextbox = tmptextbox+"\r\nIssue "+issues.get(maxDiffIssueIndex).getIssueNum()+ + " won by party "+issues.get(maxDiffIssueIndex).getParty()+"\r\n"; + //outResultFile<<"\nIssue "< (issues[maxDiffIssueIndex].ToPointer());; + + String tmpstringtextbox = ptrtmpIssue->CalculateNewRates ( ptrtmpIssuemaxDiffIssueIndex->getWiningPartyRate(), + ptrtmpIssuemaxDiffIssueIndex->getLoosingPartyRate(), + ptrtmpIssuemaxDiffIssueIndex->getParty() ); + String tmptextbox+= tmpstringtextbox; + } + }// end of for( genIndex + + } + +} diff --git a/src/main/java/com/cortez/samples/javaee7angular/rest/IssueResource.java b/src/main/java/com/cortez/samples/javaee7angular/rest/IssueResource.java index 7a06dbe..8bdbbf9 100644 --- a/src/main/java/com/cortez/samples/javaee7angular/rest/IssueResource.java +++ b/src/main/java/com/cortez/samples/javaee7angular/rest/IssueResource.java @@ -23,6 +23,8 @@ @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public class IssueResource extends Application { + + @PersistenceContext private EntityManager entityManager; diff --git a/src/main/resources/sql/create.sql b/src/main/resources/sql/create.sql index 587adf9..b112a5d 100644 --- a/src/main/resources/sql/create.sql +++ b/src/main/resources/sql/create.sql @@ -1 +1 @@ -CREATE TABLE ISSUE (ID INT NOT NULL AUTO_INCREMENT, ISSUENUM VARCHAR(50), P1RATE DECIMAL(7.5), P2RATE DECIMAL(7.5), PRIMARY KEY (ID) ); +CREATE TABLE ISSUE (ID INT NOT NULL AUTO_INCREMENT, ISSUENUM VARCHAR(50), P1RATE DECIMAL(7,5), P2RATE DECIMAL(7,5), PRIMARY KEY (ID) ); diff --git a/src/main/resources/sql/load.sql b/src/main/resources/sql/load.sql index b189d1f..28e8c29 100644 --- a/src/main/resources/sql/load.sql +++ b/src/main/resources/sql/load.sql @@ -1,15 +1,15 @@ -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (1, 'Uzumaki Naruto', 3.4, 5.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (2, 'Hatake Kakashi', 3.4, 5.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (3, 'Haruno Sakura', 3.4, 5.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (4, 'Uchiha Sasuke', 3.4, 5.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (5, 'Gaara', 3.4, 5.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (6, 'Killer Bee', 3.4, 5.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (7, 'Jiraya', 3.4, 5.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (8, 'Namikaze Minato', 3.2, 3.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (9, 'Uchiha Madara', 3.2, 3.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (10, 'Senju Hashirama', 3.2, 3.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (11, 'Might Guy', 3.2, 3.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (12, 'Hyuga Neji', 3.2, 3.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (13, 'Rock Lee', 3.2, 3.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (14, 'Uchiha Obito', 3.2, 3.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (15, 'Kurama', 3.2, 3.4) \ No newline at end of file +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (1, '1', 3.4, 5.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (2, '2', 3.4, 5.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (3, '3', 3.4, 5.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (4, '4', 3.4, 5.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (5, '5', 3.4, 5.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (6, '6', 3.4, 5.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (7, '7', 3.4, 5.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (8, '8', 3.2, 3.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (9, '9', 3.2, 3.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (10, '10', 3.2, 3.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (11, '11', 3.2, 3.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (12, '12', 3.2, 3.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (13, '13', 3.5, 3.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (14, '14', 3.2, 3.4) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (15, '15', 3.2, 3.4) \ No newline at end of file diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html index 4cc9be9..a73ee69 100644 --- a/src/main/webapp/index.html +++ b/src/main/webapp/index.html @@ -2,7 +2,7 @@ - javaee7-angular + Negotiation Application @@ -32,7 +32,7 @@ -

Java EE - Angular Application

+

Negotiation Application


@@ -82,33 +82,31 @@

Edit issue

+ required ng-maxlength="50"/> -

Add Name.

-

Name must be at least 2 characters long.

+

Add issue number. Seperate childissue with a '.'.

Name cannot be longer than 50 characters.

-
- +
+ - + - + required/> - -

Add Description.

-

Description must be at least 1 characters long.

-

Description cannot be longer than 100 characters.

+ +

Add Image URL.

+

Invalid Image URL.

- + diff --git a/src/main/webapp/script/issue.js b/src/main/webapp/script/issue.js index 49d7c80..95371a1 100644 --- a/src/main/webapp/script/issue.js +++ b/src/main/webapp/script/issue.js @@ -78,9 +78,6 @@ app.controller('issuesFormController', function ($scope, $rootScope, issueServic // Clears the form. Either by clicking the 'Clear' button in the form, or when a successfull save is performed. $scope.clearForm = function () { $scope.issue = null; - // For some reason, I was unable to clear field values with type 'url' if the value is invalid. - // This is a workaroud. Needs proper investigation. - document.getElementById('imageUrl').value = null; // Resets the form validation state. $scope.issueForm.$setPristine(); // Broadcast the event to also clear the grid selection. @@ -125,6 +122,16 @@ app.controller('issuesFormController', function ($scope, $rootScope, issueServic $rootScope.$broadcast('error'); }); }); + + + // Clears the form. Either by clicking the 'Clear' button in the form, or when a successfull save is performed. + $scope.resolve = function () { + $scope.issue = null; + // Resets the form validation state. + $scope.issueForm.$setPristine(); + // Broadcast the event to also clear the grid selection. + $rootScope.$broadcast('clear'); + }; }); // Create a controller with name alertMessagesController to bind to the feedback messages section. From c374eace9c82cea4d271362a51162c8a6af08f9e Mon Sep 17 00:00:00 2001 From: Arkadios Tsamourliadis Date: Wed, 18 May 2016 11:55:53 +0300 Subject: [PATCH 6/8] implemented issue resolving --- .../samples/javaee7angular/data/Issue.java | 113 ++++++++++++++++++ .../negotiation/Negotiation.java | 32 +++-- .../javaee7angular/rest/IssueResource.java | 9 ++ src/main/resources/sql/create.sql | 2 +- src/main/resources/sql/load.sql | 30 ++--- src/main/webapp/index.html | 1 + src/main/webapp/script/issue.js | 6 +- 7 files changed, 162 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/cortez/samples/javaee7angular/data/Issue.java b/src/main/java/com/cortez/samples/javaee7angular/data/Issue.java index 6861ee9..d10cb3b 100644 --- a/src/main/java/com/cortez/samples/javaee7angular/data/Issue.java +++ b/src/main/java/com/cortez/samples/javaee7angular/data/Issue.java @@ -86,4 +86,117 @@ public void setWinningParty() { public int hashCode() { return id.hashCode(); } + + public double getWiningPartyRate() { + if ( belongs == 1 ) return p1Rate.doubleValue(); + else return p2Rate.doubleValue(); + } + + public double getLoosingPartyRate() { + if ( belongs == 1 ) return p2Rate.doubleValue(); + else return p1Rate.doubleValue(); + } + + public String CalculateNewRates(double WinnersResolvedIssueRate, double LoosersResolvedIssueRate, int WinningParty ) { + //ofstream outResultFile( "result.txt", ios::app ); + String output=""; + output+="Old Rates for Issue "+issueNum+": "+p1Rate+", "+p2Rate+"\n"; +// outResultFile<<"Old Rates for Issue "<= 0 && Difference < 30 ) Factor = (1.0/0.3) * Difference; + else if ( Difference >=30 && Difference <= 100 ) Factor = 100; + } + else if (WinningIssueRate > 10 && WinningIssueRate <= 20 ) + { + if( Difference >= 0 && Difference < 10 ) Factor = 1.25 * Difference + 12.5; + else if( Difference >= 10 && Difference < 20 ) Factor = 25; + else if( Difference >= 20 && Difference < 40 ) Factor = ( 1.0 / 2.0 ) * Difference + 15; + else if( Difference >= 40 && Difference < 60 ) Factor = - ( 3.5 / 2.0 ) * Difference + 105; + else if( Difference >= 60 && Difference <= 100 ) Factor = - ( 0.5 / 4.0 ) * Difference + 7.5; + } + else if ( WinningIssueRate > 20 && WinningIssueRate <= 35 ) + { + if( Difference >= 0 && Difference < 10 ) Factor = 5; + else if( Difference >= 10 && Difference < 20 ) Factor = 0.75 * Difference - 2.5; + else if( Difference >= 20 && Difference < 40 ) Factor = 12.5; + else if( Difference >= 40 && Difference < 60 ) Factor = - ( 2.5 / 4.0 ) * Difference + 37.5; + else if( Difference >= 60 && Difference <= 100 ) Factor = - ( 1.0 / 4.0 ) * Difference + 15; + } + else if( WinningIssueRate > 35 && WinningIssueRate <= 55 ) { + if( Difference >= 0 && Difference < 10 ) Factor = ( 1.0 / 1.0 ) * Difference - 5; + else if( Difference >= 10 && Difference < 20 ) Factor = 5; + else if( Difference >= 20 && Difference < 40 ) Factor = - ( 0.5 / 1.0 ) * Difference + 20; + else if( Difference >= 40 && Difference <= 100 ) Factor = - 0.25 * Difference + 10; + } + else if( WinningIssueRate > 55 ) + { + if( Difference >= 0 && Difference <= 100 ) Factor = ( 1.0 / 1.0 ) * Difference - 100; + } + + return Factor/100.0; + } + + private double CalculateLoosingPartyRate(double WinningIssueRate, double Difference) { + double Factor=1; + if ( WinningIssueRate <= 10 ) + { + if( Difference >= 0 && Difference < 20 ) Factor = 25; + else if( Difference >= 20 && Difference < 30 ) Factor = ( 2.5 / 1.0 ) * Difference - 25; + else if( Difference >= 30 && Difference <= 100) Factor = 50; + } + else if (WinningIssueRate > 10 && WinningIssueRate <= 20 ) + { + if( Difference >= 0 && Difference < 30 ) Factor = 25; + else if( Difference >= 30 && Difference <= 100 ) Factor = -( 2.5 / 7.0 ) * Difference + 250 / 7; + } + else if ( WinningIssueRate > 20 && WinningIssueRate <= 35 ) + { + if( Difference >= 0 && Difference < 40 ) Factor = 50; + else if( Difference >= 40 && Difference < 50 ) Factor = -( 2.5 / 1.0 ) * Difference + 150; + else if( Difference >= 50 && Difference <= 100 ) Factor = -( 0.5 / 1.0 ) * Difference + 50; + } + else if( WinningIssueRate > 35 && WinningIssueRate <= 55 ) { + if( Difference >= 0 && Difference < 20 ) Factor = 75; + else if( Difference >= 20 && Difference < 30 ) Factor = -( 2.5 / 1.0 ) * Difference + 125; + else if( Difference >= 30 && Difference < 55 ) Factor = 50; + else if( Difference >= 55 && Difference < 60 ) Factor = -5 * Difference + 325; + else if( Difference >= 60 && Difference <= 100 ) Factor = -( 2.5 / 4.0 ) * Difference + 62.5; + } + else if( WinningIssueRate > 55 ) + { + if( Difference >= 0 && Difference < 30 ) Factor = 100; + else if( Difference >= 30 && Difference < 40 ) Factor = -( 2.5 / 1.0 ) * Difference + 175; + else if( Difference >= 40 && Difference < 50 ) Factor = 75; + else if( Difference >= 50 && Difference < 60 ) Factor = -( 2.5 / 1.0 ) * Difference + 200; + else if( Difference >= 60 && Difference <= 100 ) Factor = -( 5.0 / 4.0 ) * Difference + 125; + } + return Factor/100.0; + } + } diff --git a/src/main/java/com/cortez/samples/javaee7angular/negotiation/Negotiation.java b/src/main/java/com/cortez/samples/javaee7angular/negotiation/Negotiation.java index 35b75c4..7a5a4ff 100644 --- a/src/main/java/com/cortez/samples/javaee7angular/negotiation/Negotiation.java +++ b/src/main/java/com/cortez/samples/javaee7angular/negotiation/Negotiation.java @@ -26,6 +26,15 @@ public class Negotiation { @PersistenceContext(unitName = "myPU") private EntityManager em; + public String performNegotiation() { + List issuesList = getAllIssues(); + String output = CalculateNormRates(issuesList); + output += resolveIssues(issuesList); + + + System.out.println("output: \n"+output); + return output; + } public List getAllIssues() { Query query = em.createNamedQuery("Issue.findAll"); @@ -64,12 +73,14 @@ private String CalculateNormRates(List issues) { calcTextBox=calcTextBox+"\r\nNormalized rates for Issue "+issue.getIssueNum()+" : "+ issue.getP1Rate()+", "+issue.getP2Rate()+"\r\n"; } + //System.out.println("CalculateNormRates: \n"+calcTextBox); return calcTextBox; } - private: void resolveIssues(List issues) { + private String resolveIssues(List issues) { //ofstream outResultFile( "result.txt", ios::app ); + String tmptextbox=""; //At each iteration an Issue will be Resolved for (int genIndex=0; genIndex < issues.size(); genIndex++) { @@ -90,25 +101,26 @@ private String CalculateNormRates(List issues) { issues.get(maxDiffIssueIndex).setWinningParty(); //This Issue has just been resolved - String tmptextbox=""; tmptextbox = tmptextbox+"\r\nIssue "+issues.get(maxDiffIssueIndex).getIssueNum()+ - " won by party "+issues.get(maxDiffIssueIndex).getParty()+"\r\n"; + " won by party "+issues.get(maxDiffIssueIndex).getBelongs()+"\r\n"; //outResultFile<<"\nIssue "< (issues[maxDiffIssueIndex].ToPointer());; - - String tmpstringtextbox = ptrtmpIssue->CalculateNewRates ( ptrtmpIssuemaxDiffIssueIndex->getWiningPartyRate(), - ptrtmpIssuemaxDiffIssueIndex->getLoosingPartyRate(), - ptrtmpIssuemaxDiffIssueIndex->getParty() ); - String tmptextbox+= tmpstringtextbox; + String tmpstringtextbox = issue.CalculateNewRates ( issues.get(maxDiffIssueIndex).getWiningPartyRate(), + issues.get(maxDiffIssueIndex).getLoosingPartyRate(), + issues.get(maxDiffIssueIndex).getBelongs()); + tmptextbox+= tmpstringtextbox; } }// end of for( genIndex - + + //System.out.println("----FINAL resolved: \n"+tmptextbox); + return tmptextbox; } } diff --git a/src/main/java/com/cortez/samples/javaee7angular/rest/IssueResource.java b/src/main/java/com/cortez/samples/javaee7angular/rest/IssueResource.java index 8bdbbf9..d5c723c 100644 --- a/src/main/java/com/cortez/samples/javaee7angular/rest/IssueResource.java +++ b/src/main/java/com/cortez/samples/javaee7angular/rest/IssueResource.java @@ -1,6 +1,7 @@ package com.cortez.samples.javaee7angular.rest; import com.cortez.samples.javaee7angular.data.Issue; +import com.cortez.samples.javaee7angular.negotiation.Negotiation; import com.cortez.samples.javaee7angular.pagination.PaginatedListWrapper; import javax.ejb.Stateless; @@ -11,6 +12,7 @@ import javax.ws.rs.core.Application; import javax.ws.rs.core.MediaType; import java.util.List; +import javax.ejb.EJB; /** * REST Service to expose the data to display in the UI grid. @@ -27,6 +29,9 @@ public class IssueResource extends Application { @PersistenceContext private EntityManager entityManager; + + @EJB + private Negotiation neg; private Integer countIssues() { Query query = entityManager.createQuery("SELECT COUNT(p.id) FROM Issue p"); @@ -74,8 +79,12 @@ public PaginatedListWrapper listIssues(@DefaultValue("1") @GET @Path("{id}") public Issue getIssue(@PathParam("id") Long id) { + if (id == -1){ + neg.performNegotiation(); + } return entityManager.find(Issue.class, id); } + @POST public Issue saveIssue(Issue issue) { diff --git a/src/main/resources/sql/create.sql b/src/main/resources/sql/create.sql index b112a5d..3536b21 100644 --- a/src/main/resources/sql/create.sql +++ b/src/main/resources/sql/create.sql @@ -1 +1 @@ -CREATE TABLE ISSUE (ID INT NOT NULL AUTO_INCREMENT, ISSUENUM VARCHAR(50), P1RATE DECIMAL(7,5), P2RATE DECIMAL(7,5), PRIMARY KEY (ID) ); +CREATE TABLE ISSUE (ID INT NOT NULL AUTO_INCREMENT, ISSUENUM VARCHAR(50), P1RATE DECIMAL(7,5), P2RATE DECIMAL(7,5), BELONGS smallint(1), PRIMARY KEY (ID) ); diff --git a/src/main/resources/sql/load.sql b/src/main/resources/sql/load.sql index 28e8c29..85f3959 100644 --- a/src/main/resources/sql/load.sql +++ b/src/main/resources/sql/load.sql @@ -1,15 +1,15 @@ -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (1, '1', 3.4, 5.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (2, '2', 3.4, 5.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (3, '3', 3.4, 5.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (4, '4', 3.4, 5.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (5, '5', 3.4, 5.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (6, '6', 3.4, 5.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (7, '7', 3.4, 5.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (8, '8', 3.2, 3.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (9, '9', 3.2, 3.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (10, '10', 3.2, 3.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (11, '11', 3.2, 3.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (12, '12', 3.2, 3.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (13, '13', 3.5, 3.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (14, '14', 3.2, 3.4) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE) VALUES (15, '15', 3.2, 3.4) \ No newline at end of file +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (1, '1', 3.4, 5.4, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (2, '2', 3.4, 5.4, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (3, '3', 3.4, 5.4, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (4, '4', 3.4, 5.4, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (5, '5', 3.4, 5.4, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (6, '6', 3.4, 5.4, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (7, '7', 3.4, 5.4, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (8, '8', 3.2, 3.4, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (9, '9', 3.2, 3.4, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (10, '10', 3.2, 3.4, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (11, '11', 3.2, 3.4, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (12, '12', 3.2, 3.4, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (13, '13', 3.5, 3.4, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (14, '14', 3.2, 3.4, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (15, '15', 3.2, 3.4, 0) \ No newline at end of file diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html index a73ee69..9222df2 100644 --- a/src/main/webapp/index.html +++ b/src/main/webapp/index.html @@ -125,6 +125,7 @@

Edit issue

+
diff --git a/src/main/webapp/script/issue.js b/src/main/webapp/script/issue.js index 95371a1..3f3579c 100644 --- a/src/main/webapp/script/issue.js +++ b/src/main/webapp/script/issue.js @@ -126,11 +126,7 @@ app.controller('issuesFormController', function ($scope, $rootScope, issueServic // Clears the form. Either by clicking the 'Clear' button in the form, or when a successfull save is performed. $scope.resolve = function () { - $scope.issue = null; - // Resets the form validation state. - $scope.issueForm.$setPristine(); - // Broadcast the event to also clear the grid selection. - $rootScope.$broadcast('clear'); + issueService.get({id: -1}); }; }); From ddf66f7ed6b877185d3e09083051d31f90d37e42 Mon Sep 17 00:00:00 2001 From: Arkadios Tsamourliadis Date: Wed, 18 May 2016 18:49:08 +0300 Subject: [PATCH 7/8] Revert "Merge branch 'master' of https://github.com/atsamour/Negotiation" This reverts commit ff2fba1752e1d362e09d341954ee302fa72968ca, reversing changes made to c374eace9c82cea4d271362a51162c8a6af08f9e. --- Form1.h | 720 ------------------------------------------------- IssueClass.cpp | 128 --------- IssueClass.h | 51 ---- main.cpp | 210 --------------- 4 files changed, 1109 deletions(-) delete mode 100644 Form1.h delete mode 100644 IssueClass.cpp delete mode 100644 IssueClass.h delete mode 100644 main.cpp diff --git a/Form1.h b/Form1.h deleted file mode 100644 index 165cdf2..0000000 --- a/Form1.h +++ /dev/null @@ -1,720 +0,0 @@ -#include "IssueClass.h" -#include -#include - -#include "stdafx.h" -#include -#include - -#include - -#include -#include - -#pragma once - -namespace Neg_vis_01 { - - using namespace System; - using namespace System::ComponentModel; - using namespace System::Collections; - using namespace System::Windows::Forms; - using namespace System::Data; - using namespace System::Drawing; - //using namespace System::Text::RegularExpressions; - - //using namespace System::IO; - - - using namespace std; - using namespace msclr::interop; - - // for ManagedTOSTL function - // using namespace System::String; - - /// - /// Summary for Form1 - /// - public ref class Form1 : public System::Windows::Forms::Form - { - public: - Form1(void) - { - InitializeComponent(); - // - //TODO: Add the constructor code here - // - } - - protected: - /// - /// Clean up any resources being used. - /// - ~Form1() - { - if (components) - { - delete components; - } - } - private: System::Windows::Forms::SplitContainer^ splitContainer1; - private: System::Windows::Forms::Button^ button3; - - protected: - - private: System::Windows::Forms::TextBox^ textBox1; - private: System::Windows::Forms::Button^ button2; - private: System::Windows::Forms::Button^ button1; - private: System::Windows::Forms::MaskedTextBox^ maskedTextBox3; - private: System::Windows::Forms::MaskedTextBox^ maskedTextBox2; - private: System::Windows::Forms::Label^ issueNumLabel; - private: System::Windows::Forms::MaskedTextBox^ maskedTextBox1; - private: System::Windows::Forms::Label^ label2; - private: System::Windows::Forms::Label^ label3; - private: System::Windows::Forms::Label^ label4; - private: System::Windows::Forms::Label^ label7; - private: System::Windows::Forms::Label^ label6; - private: System::Windows::Forms::Label^ label5; - private: System::Windows::Forms::Button^ button4; - private: System::Windows::Forms::MaskedTextBox^ maskedTextBox4; - private: System::Windows::Forms::Panel^ panel1; - private: System::Windows::Forms::Label^ issueNumLabel1; - private: System::Windows::Forms::TextBox^ ResultsTextBox; - - private: System::Windows::Forms::Label^ issueNumLabel0; - private: System::Windows::Forms::Label^ label9; - private: System::Windows::Forms::Label^ issueChild; - - private: System::Windows::Forms::Panel^ panel2; - private: System::Windows::Forms::Panel^ panel3; - private: System::Windows::Forms::Label^ parentIssue; - private: System::Windows::Forms::Label^ issueNumLabel2; - private: System::Windows::Forms::Label^ label8; - private: System::Windows::Forms::Label^ issueNumLabel3; - private: System::Windows::Forms::TextBox^ textBox2; - - private: - /// - /// Required designer variable. - /// - System::ComponentModel::Container ^components; - -#pragma region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - void InitializeComponent(void) - { - this->splitContainer1 = (gcnew System::Windows::Forms::SplitContainer()); - this->parentIssue = (gcnew System::Windows::Forms::Label()); - this->issueNumLabel2 = (gcnew System::Windows::Forms::Label()); - this->label8 = (gcnew System::Windows::Forms::Label()); - this->panel3 = (gcnew System::Windows::Forms::Panel()); - this->label7 = (gcnew System::Windows::Forms::Label()); - this->label6 = (gcnew System::Windows::Forms::Label()); - this->label5 = (gcnew System::Windows::Forms::Label()); - this->textBox1 = (gcnew System::Windows::Forms::TextBox()); - this->button3 = (gcnew System::Windows::Forms::Button()); - this->panel1 = (gcnew System::Windows::Forms::Panel()); - this->issueNumLabel1 = (gcnew System::Windows::Forms::Label()); - this->button4 = (gcnew System::Windows::Forms::Button()); - this->ResultsTextBox = (gcnew System::Windows::Forms::TextBox()); - this->issueNumLabel0 = (gcnew System::Windows::Forms::Label()); - this->label9 = (gcnew System::Windows::Forms::Label()); - this->panel2 = (gcnew System::Windows::Forms::Panel()); - this->label3 = (gcnew System::Windows::Forms::Label()); - this->label2 = (gcnew System::Windows::Forms::Label()); - this->maskedTextBox3 = (gcnew System::Windows::Forms::MaskedTextBox()); - this->maskedTextBox2 = (gcnew System::Windows::Forms::MaskedTextBox()); - this->issueNumLabel = (gcnew System::Windows::Forms::Label()); - this->maskedTextBox1 = (gcnew System::Windows::Forms::MaskedTextBox()); - this->maskedTextBox4 = (gcnew System::Windows::Forms::MaskedTextBox()); - this->label4 = (gcnew System::Windows::Forms::Label()); - this->issueChild = (gcnew System::Windows::Forms::Label()); - this->button2 = (gcnew System::Windows::Forms::Button()); - this->button1 = (gcnew System::Windows::Forms::Button()); - this->issueNumLabel3 = (gcnew System::Windows::Forms::Label()); - this->textBox2 = (gcnew System::Windows::Forms::TextBox()); - (cli::safe_cast(this->splitContainer1))->BeginInit(); - this->splitContainer1->Panel1->SuspendLayout(); - this->splitContainer1->Panel2->SuspendLayout(); - this->splitContainer1->SuspendLayout(); - this->panel3->SuspendLayout(); - this->panel1->SuspendLayout(); - this->panel2->SuspendLayout(); - this->SuspendLayout(); - // - // splitContainer1 - // - this->splitContainer1->Dock = System::Windows::Forms::DockStyle::Fill; - this->splitContainer1->Location = System::Drawing::Point(0, 0); - this->splitContainer1->Name = L"splitContainer1"; - // - // splitContainer1.Panel1 - // - this->splitContainer1->Panel1->Controls->Add(this->parentIssue); - this->splitContainer1->Panel1->Controls->Add(this->issueNumLabel2); - this->splitContainer1->Panel1->Controls->Add(this->label8); - this->splitContainer1->Panel1->Controls->Add(this->panel3); - this->splitContainer1->Panel1->Controls->Add(this->panel1); - this->splitContainer1->Panel1->Controls->Add(this->panel2); - this->splitContainer1->Panel1->Controls->Add(this->maskedTextBox4); - this->splitContainer1->Panel1->Controls->Add(this->label4); - this->splitContainer1->Panel1->Controls->Add(this->issueChild); - this->splitContainer1->Panel1->Controls->Add(this->button2); - this->splitContainer1->Panel1->Controls->Add(this->button1); - this->splitContainer1->Panel1->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::splitContainer1_Panel1_Paint); - // - // splitContainer1.Panel2 - // - this->splitContainer1->Panel2->Controls->Add(this->issueNumLabel3); - this->splitContainer1->Panel2->Controls->Add(this->textBox2); - this->splitContainer1->Size = System::Drawing::Size(717, 428); - this->splitContainer1->SplitterDistance = 433; - this->splitContainer1->TabIndex = 0; - // - // parentIssue - // - this->parentIssue->AutoSize = true; - this->parentIssue->Location = System::Drawing::Point(276, 91); - this->parentIssue->Name = L"parentIssue"; - this->parentIssue->Size = System::Drawing::Size(0, 13); - this->parentIssue->TabIndex = 21; - // - // issueNumLabel2 - // - this->issueNumLabel2->AutoSize = true; - this->issueNumLabel2->Location = System::Drawing::Point(177, 91); - this->issueNumLabel2->Name = L"issueNumLabel2"; - this->issueNumLabel2->Size = System::Drawing::Size(93, 13); - this->issueNumLabel2->TabIndex = 20; - this->issueNumLabel2->Text = L"parent issue name"; - // - // label8 - // - this->label8->AutoSize = true; - this->label8->Location = System::Drawing::Point(289, 63); - this->label8->Name = L"label8"; - this->label8->Size = System::Drawing::Size(87, 13); - this->label8->TabIndex = 19; - this->label8->Text = L"subissue counter"; - // - // panel3 - // - this->panel3->Controls->Add(this->label7); - this->panel3->Controls->Add(this->label6); - this->panel3->Controls->Add(this->label5); - this->panel3->Controls->Add(this->textBox1); - this->panel3->Controls->Add(this->button3); - this->panel3->Location = System::Drawing::Point(4, 112); - this->panel3->Name = L"panel3"; - this->panel3->Size = System::Drawing::Size(219, 316); - this->panel3->TabIndex = 18; - // - // label7 - // - this->label7->AutoSize = true; - this->label7->Location = System::Drawing::Point(127, 6); - this->label7->Name = L"label7"; - this->label7->Size = System::Drawing::Size(49, 13); - this->label7->TabIndex = 13; - this->label7->Text = L"P 2 Rate"; - // - // label6 - // - this->label6->AutoSize = true; - this->label6->Location = System::Drawing::Point(72, 6); - this->label6->Name = L"label6"; - this->label6->Size = System::Drawing::Size(49, 13); - this->label6->TabIndex = 12; - this->label6->Text = L"P 1 Rate"; - // - // label5 - // - this->label5->AutoSize = true; - this->label5->Location = System::Drawing::Point(9, 6); - this->label5->Name = L"label5"; - this->label5->Size = System::Drawing::Size(32, 13); - this->label5->TabIndex = 11; - this->label5->Text = L"Issue"; - // - // textBox1 - // - this->textBox1->Location = System::Drawing::Point(3, 22); - this->textBox1->Multiline = true; - this->textBox1->Name = L"textBox1"; - this->textBox1->ScrollBars = System::Windows::Forms::ScrollBars::Vertical; - this->textBox1->Size = System::Drawing::Size(213, 267); - this->textBox1->TabIndex = 6; - // - // button3 - // - this->button3->Cursor = System::Windows::Forms::Cursors::Arrow; - this->button3->Location = System::Drawing::Point(0, 295); - this->button3->Name = L"button3"; - this->button3->Size = System::Drawing::Size(65, 21); - this->button3->TabIndex = 7; - this->button3->Text = L"From file"; - this->button3->UseVisualStyleBackColor = true; - this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click); - // - // panel1 - // - this->panel1->Controls->Add(this->issueNumLabel1); - this->panel1->Controls->Add(this->button4); - this->panel1->Controls->Add(this->ResultsTextBox); - this->panel1->Controls->Add(this->issueNumLabel0); - this->panel1->Controls->Add(this->label9); - this->panel1->Location = System::Drawing::Point(229, 115); - this->panel1->Name = L"panel1"; - this->panel1->Size = System::Drawing::Size(201, 313); - this->panel1->TabIndex = 17; - // - // issueNumLabel1 - // - this->issueNumLabel1->AutoSize = true; - this->issueNumLabel1->Location = System::Drawing::Point(124, 51); - this->issueNumLabel1->Name = L"issueNumLabel1"; - this->issueNumLabel1->Size = System::Drawing::Size(40, 13); - this->issueNumLabel1->TabIndex = 16; - this->issueNumLabel1->Text = L"Party 2"; - // - // button4 - // - this->button4->Cursor = System::Windows::Forms::Cursors::Arrow; - this->button4->Location = System::Drawing::Point(55, 3); - this->button4->Name = L"button4"; - this->button4->Size = System::Drawing::Size(63, 45); - this->button4->TabIndex = 15; - this->button4->Text = L"Resolve Issues"; - this->button4->UseVisualStyleBackColor = true; - this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click); - // - // ResultsTextBox - // - this->ResultsTextBox->Location = System::Drawing::Point(6, 66); - this->ResultsTextBox->Multiline = true; - this->ResultsTextBox->Name = L"ResultsTextBox"; - this->ResultsTextBox->ReadOnly = true; - this->ResultsTextBox->ScrollBars = System::Windows::Forms::ScrollBars::Vertical; - this->ResultsTextBox->Size = System::Drawing::Size(192, 238); - this->ResultsTextBox->TabIndex = 16; - // - // issueNumLabel0 - // - this->issueNumLabel0->AutoSize = true; - this->issueNumLabel0->Location = System::Drawing::Point(58, 51); - this->issueNumLabel0->Name = L"issueNumLabel0"; - this->issueNumLabel0->Size = System::Drawing::Size(40, 13); - this->issueNumLabel0->TabIndex = 16; - this->issueNumLabel0->Text = L"Party 1"; - // - // label9 - // - this->label9->AutoSize = true; - this->label9->Location = System::Drawing::Point(3, 51); - this->label9->Name = L"label9"; - this->label9->Size = System::Drawing::Size(32, 13); - this->label9->TabIndex = 13; - this->label9->Text = L"Issue"; - // - // panel2 - // - this->panel2->Controls->Add(this->label3); - this->panel2->Controls->Add(this->label2); - this->panel2->Controls->Add(this->maskedTextBox3); - this->panel2->Controls->Add(this->maskedTextBox2); - this->panel2->Controls->Add(this->issueNumLabel); - this->panel2->Controls->Add(this->maskedTextBox1); - this->panel2->Location = System::Drawing::Point(120, 3); - this->panel2->Name = L"panel2"; - this->panel2->Size = System::Drawing::Size(244, 55); - this->panel2->TabIndex = 16; - // - // label3 - // - this->label3->AutoSize = true; - this->label3->Location = System::Drawing::Point(155, 12); - this->label3->Name = L"label3"; - this->label3->Size = System::Drawing::Size(66, 13); - this->label3->TabIndex = 9; - this->label3->Text = L"Party 2 Rate"; - // - // label2 - // - this->label2->AutoSize = true; - this->label2->Location = System::Drawing::Point(83, 12); - this->label2->Name = L"label2"; - this->label2->Size = System::Drawing::Size(66, 13); - this->label2->TabIndex = 8; - this->label2->Text = L"Party 1 Rate"; - // - // maskedTextBox3 - // - this->maskedTextBox3->Location = System::Drawing::Point(172, 32); - this->maskedTextBox3->Name = L"maskedTextBox3"; - this->maskedTextBox3->Size = System::Drawing::Size(23, 20); - this->maskedTextBox3->TabIndex = 3; - // - // maskedTextBox2 - // - this->maskedTextBox2->Location = System::Drawing::Point(106, 32); - this->maskedTextBox2->Name = L"maskedTextBox2"; - this->maskedTextBox2->Size = System::Drawing::Size(26, 20); - this->maskedTextBox2->TabIndex = 2; - // - // issueNumLabel - // - this->issueNumLabel->AutoSize = true; - this->issueNumLabel->Location = System::Drawing::Point(5, 12); - this->issueNumLabel->Name = L"issueNumLabel"; - this->issueNumLabel->Size = System::Drawing::Size(72, 13); - this->issueNumLabel->TabIndex = 1; - this->issueNumLabel->Text = L"Issue Number"; - // - // maskedTextBox1 - // - this->maskedTextBox1->Location = System::Drawing::Point(17, 32); - this->maskedTextBox1->Name = L"maskedTextBox1"; - this->maskedTextBox1->Size = System::Drawing::Size(51, 20); - this->maskedTextBox1->TabIndex = 0; - // - // maskedTextBox4 - // - this->maskedTextBox4->Location = System::Drawing::Point(120, 79); - this->maskedTextBox4->Name = L"maskedTextBox4"; - this->maskedTextBox4->Size = System::Drawing::Size(51, 20); - this->maskedTextBox4->TabIndex = 14; - // - // label4 - // - this->label4->AutoSize = true; - this->label4->Location = System::Drawing::Point(177, 63); - this->label4->Name = L"label4"; - this->label4->Size = System::Drawing::Size(37, 13); - this->label4->TabIndex = 10; - this->label4->Text = L"Issues"; - // - // issueChild - // - this->issueChild->AutoSize = true; - this->issueChild->Location = System::Drawing::Point(377, 63); - this->issueChild->Name = L"issueChild"; - this->issueChild->Size = System::Drawing::Size(13, 13); - this->issueChild->TabIndex = 12; - this->issueChild->Text = L"0"; - // - // button2 - // - this->button2->Location = System::Drawing::Point(3, 63); - this->button2->Name = L"button2"; - this->button2->Size = System::Drawing::Size(115, 41); - this->button2->TabIndex = 5; - this->button2->Text = L"add subissues to issue..."; - this->button2->UseVisualStyleBackColor = true; - this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click); - // - // button1 - // - this->button1->ForeColor = System::Drawing::SystemColors::ControlText; - this->button1->Location = System::Drawing::Point(3, 15); - this->button1->Name = L"button1"; - this->button1->Size = System::Drawing::Size(115, 29); - this->button1->TabIndex = 4; - this->button1->Text = L"save issue"; - this->button1->UseVisualStyleBackColor = true; - this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click); - // - // issueNumLabel3 - // - this->issueNumLabel3->AutoSize = true; - this->issueNumLabel3->Location = System::Drawing::Point(5, 45); - this->issueNumLabel3->Name = L"issueNumLabel3"; - this->issueNumLabel3->Size = System::Drawing::Size(63, 13); - this->issueNumLabel3->TabIndex = 1; - this->issueNumLabel3->Text = L"calculations"; - // - // textBox2 - // - this->textBox2->Location = System::Drawing::Point(8, 63); - this->textBox2->Multiline = true; - this->textBox2->Name = L"textBox2"; - this->textBox2->ReadOnly = true; - this->textBox2->ScrollBars = System::Windows::Forms::ScrollBars::Both; - this->textBox2->Size = System::Drawing::Size(269, 353); - this->textBox2->TabIndex = 0; - // - // Form1 - // - this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); - this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; - this->ClientSize = System::Drawing::Size(717, 428); - this->Controls->Add(this->splitContainer1); - this->Name = L"Form1"; - this->Text = L"Negotiation 1.0 GUI"; - this->splitContainer1->Panel1->ResumeLayout(false); - this->splitContainer1->Panel1->PerformLayout(); - this->splitContainer1->Panel2->ResumeLayout(false); - this->splitContainer1->Panel2->PerformLayout(); - (cli::safe_cast(this->splitContainer1))->EndInit(); - this->splitContainer1->ResumeLayout(false); - this->panel3->ResumeLayout(false); - this->panel3->PerformLayout(); - this->panel1->ResumeLayout(false); - this->panel1->PerformLayout(); - this->panel2->ResumeLayout(false); - this->panel2->PerformLayout(); - this->ResumeLayout(false); - - } -#pragma endregion - - private: int currentParent; - private: - static System::Collections::Generic::List ^issues - = gcnew System::Collections::Generic::List(); - -/////////////////////////////////////////////////////////////////////////////////////////////////////// -private: System::String^ CalculateNormRates(System::Collections::Generic::List ^issues) -{ - //ofstream outResultFile( "result.txt", ios::app ); - double p1sum=0; - double p2sum=0; - IssueClass* ptrtmpIssue; - System::String^ calcTextBox=""; - - for (int i=0; iCount; i++) - { - ptrtmpIssue = reinterpret_cast (issues[i].ToPointer()); - p1sum += ptrtmpIssue->getP1Rate(); - p2sum += ptrtmpIssue->getP2Rate(); - /////////////////////////// - - System::String^ tmpIsnum= gcnew String(ptrtmpIssue->IssueNum.c_str()); - calcTextBox=calcTextBox+"Calculating SumS p1, p2: "+p1sum+", "+p2sum+"\r\n"; - calcTextBox=calcTextBox+" Issue name: "+tmpIsnum+" rates: "+ptrtmpIssue->getP1Rate()+" "+ptrtmpIssue->getP2Rate()+"\r\n"; - } - //cout<<"\nSum of Party 1 Rates:"<Count; i++) { - ptrtmpIssue = reinterpret_cast (issues[i].ToPointer()); - ptrtmpIssue->normalizeRates(p1sum, p2sum); - //cout<<"Normalized rates for Issue"<IssueNum.c_str()); - calcTextBox=calcTextBox+"\r\nNormalized rates for Issue "+tmpIsnum+" : "+ - ptrtmpIssue->getP1Rate()+", "+ptrtmpIssue->getP2Rate()+"\r\n"; - - } - return calcTextBox; -} - -/////////////////////////////////////////////////////////////////////////////////////////////////////// -private: void resolveIssues(System::Collections::Generic::List ^issues) -{ - //ofstream outResultFile( "result.txt", ios::app ); - - IssueClass* ptrtmpIssue; - - //At each iteration an Issue will be Resolved - for (int genIndex=0; genIndex < issues->Count; genIndex++) - { - double maxDiff=0; - int maxDiffIssueIndex; - - //Find an Issue to Resolve - for (int i=0; iCount; i++) - { - ptrtmpIssue = reinterpret_cast (issues[i].ToPointer()); - if (ptrtmpIssue->Resolved()) - { //Issue already Resolved - continue; - } - if ( ptrtmpIssue->getMrkDiff() >= maxDiff ) - { - maxDiff = ptrtmpIssue->getMrkDiff(); - maxDiffIssueIndex = i; - } - } - ptrtmpIssue = reinterpret_cast (issues[maxDiffIssueIndex].ToPointer()); - ptrtmpIssue->setWinningParty(); //This Issue has just been resolved - - - System::String^ tmptextbox=""; - tmptextbox = tmptextbox+"\r\nIssue "+ptrtmpIssue->getIssueNum()+ - " won by party "+ptrtmpIssue->getParty()+"\r\n"; - textBox2->Text +=tmptextbox; - //outResultFile<<"\nIssue "<Count; i++) - { - ptrtmpIssue = reinterpret_cast (issues[i].ToPointer()); - if (ptrtmpIssue->Resolved()) - { //Does not have to Calculate new Rates for a resolved Issue - continue; - } - - IssueClass* ptrtmpIssuemaxDiffIssueIndex = reinterpret_cast (issues[maxDiffIssueIndex].ToPointer());; - - string tmpstringtextbox = ptrtmpIssue->CalculateNewRates ( ptrtmpIssuemaxDiffIssueIndex->getWiningPartyRate(), - ptrtmpIssuemaxDiffIssueIndex->getLoosingPartyRate(), - ptrtmpIssuemaxDiffIssueIndex->getParty() ); - System::String^ tmptextbox= gcnew String(tmpstringtextbox.c_str()); - textBox2->Text +=tmptextbox; - } - }// end of for( genIndex - -} - -//save issue -private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { - IssueClass* ptrtmpIssue; - if(this->issueChild->Text=="1") {//prwto paidi - ptrtmpIssue = reinterpret_cast (issues[currentParent].ToPointer()); - ptrtmpIssue->alterToSubIssue( marshal_as(this->parentIssue->Text)+","+ - marshal_as(this->maskedTextBox1->Text), - marshal_as(this->maskedTextBox2->Text), - marshal_as(this->maskedTextBox3->Text) ); - //Kratame ton ari8mo tou paidiou sto Label issueChild, xrhsimopoiontas to ws counter - std::istringstream chldTxt; - double chldDbl; - chldTxt.str(marshal_as(this->issueChild->Text)); - chldTxt>>chldDbl; - chldDbl++; - this->issueChild->Text = System::Convert::ToString(chldDbl); - //currentParent=IssueIndex; - } - else if(this->issueChild->Text=="0") {//kanonikh eisagwgh - ptrtmpIssue = new IssueClass( - marshal_as(this->maskedTextBox1->Text), - marshal_as(this->maskedTextBox2->Text), - marshal_as(this->maskedTextBox3->Text) ); - issues->Add(System::IntPtr(ptrtmpIssue)); - } - else {//eisagwgh deuerou paidiou kai meta - ptrtmpIssue = new IssueClass( marshal_as(this->parentIssue->Text)+","+ - marshal_as(this->maskedTextBox1->Text), - marshal_as(this->maskedTextBox2->Text), - marshal_as(this->maskedTextBox3->Text) ); - issues->Add(System::IntPtr(ptrtmpIssue)); - //Kratame ton ari8mo tou paidiou sto Label issueChild, xrhsimopoiontas to ws counter - std::istringstream chldTxt; - double chldDbl; - chldTxt.str(marshal_as(this->issueChild->Text)); - chldTxt>>chldDbl; - chldDbl++; - this->issueChild->Text = System::Convert::ToString(chldDbl); - //currentParent=IssueIndex; - - } - - //!!!!!!!se periptwsh prwtou paidiou na diagrafetai o goneas apo to textbox!!!<--add - - - //Convert the string - String^ MSIssueNum = gcnew String(ptrtmpIssue->IssueNum.c_str()); - this->textBox1->Text+=MSIssueNum+"\t\t" - +this->maskedTextBox2->Text+"\t"+this->maskedTextBox3->Text+"\r\n"; - this->maskedTextBox1->Clear(); - this->maskedTextBox2->Clear(); - this->maskedTextBox3->Clear(); - - } - - //add subissues to issue... -private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { - this->issueChild->Text="0"; - //this->maskedTextBox1->Hide(); - - bool foundFlag=0; - int IssueIndex; - for (IssueIndex=0; IssueIndexCount; IssueIndex++) - { - IssueClass* ptrtmpIssue = reinterpret_cast (issues[IssueIndex].ToPointer()); - if (this->maskedTextBox4->Text==ptrtmpIssue->getIssueNum()) { - foundFlag=1; break; } - } - //Not found an issue with Inum IssueNum - if (!foundFlag) - { - this->label4->Text="No such Issue found "; //+this->maskedTextBox4->Text; - this->maskedTextBox2->Clear(); - this->maskedTextBox3->Clear(); - this->maskedTextBox4->Clear(); - return; - } - this->label4->Text="subissues"; - this->parentIssue->Text=this->maskedTextBox4->Text; - //Kratame ton ari8mo tou paidiou sto Label issueChild, xrhsimopoiontas to ws counter - std::istringstream chldTxt; - double chldDbl; - chldTxt.str(marshal_as(this->issueChild->Text)); - chldTxt>>chldDbl; - chldDbl++; - this->issueChild->Text = System::Convert::ToString(chldDbl); - currentParent=IssueIndex; - } - - //From file -private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) { - OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog; - if(openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK) - { - System::IO::StreamReader ^ sr = gcnew - System::IO::StreamReader(openFileDialog1->FileName); - IssueClass* ptrtmpIssue; - while(sr->Peek()>=0) { - String ^line = sr->ReadLine(); - this->textBox1->Text+=line+"\r\n"; - array^chars = {'\t'}; - array^ s = line->Split( chars ); - String^ s1=s[0]; - String^ p1=s[1]; - String^ p2=s[2]; - ptrtmpIssue = new IssueClass( marshal_as(s1), - marshal_as(p1), marshal_as(p2) ); - issues->Add(System::IntPtr(ptrtmpIssue)); - } - //MessageBox::Show(sr->ReadToEnd()); - sr->Close(); - } - - } -private: System::Void splitContainer1_Panel1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) { - } - - //Resolve Issues -private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) { - textBox2->Text = CalculateNormRates(issues); - //issues->Order( - resolveIssues(issues); - - IssueClass* ptrtmpIssue; - - //Printing final results - for (int i=0; iCount; i++) - { - ptrtmpIssue = reinterpret_cast (issues[i].ToPointer()); - //ptrtmpIssue->printIssueDetails(); - - System::String^ TextBoxString = gcnew System::String(ptrtmpIssue->IssueNum.c_str()); - - if ( ptrtmpIssue->getParty()==1 ) - ResultsTextBox->Text=ResultsTextBox->Text+TextBoxString+"\t\t"+"1"+"\t"+"0"+"\r\n"; - else if ( ptrtmpIssue->getParty()==2 ) - ResultsTextBox->Text=ResultsTextBox->Text+TextBoxString+"\t\t"+"0"+"\t"+"1"+"\r\n"; - else - ResultsTextBox->Text=ResultsTextBox->Text+TextBoxString+"\r\n"; - } - - } -}; -} - diff --git a/IssueClass.cpp b/IssueClass.cpp deleted file mode 100644 index a162b97..0000000 --- a/IssueClass.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include "IssueClass.h" -#include -#include -#include -#include - -using namespace std; - -unsigned int IssueClass::IssuesCnt; //<---Need this?? - -/////////////////////////////////////////////////////////////////////////////////////////////////////// -void IssueClass::CalculateNewRates(double WinnersResolvedIssueRate, double LoosersResolvedIssueRate, int WinningParty ) -{ - ofstream outResultFile( "result.txt", ios::app ); - cout<<"Old Rates for Issue "<= 0 && Difference < 30 ) Factor = (1.0/0.3) * Difference; - else if ( Difference >=30 && Difference <= 100 ) Factor = 100; - } - else if (WinningIssueRate > 10 && WinningIssueRate <= 20 ) - { - if( Difference >= 0 && Difference < 10 ) Factor = 1.25 * Difference + 12.5; - else if( Difference >= 10 && Difference < 20 ) Factor = 25; - else if( Difference >= 20 && Difference < 40 ) Factor = ( 1.0 / 2.0 ) * Difference + 15; - else if( Difference >= 40 && Difference < 60 ) Factor = - ( 3.5 / 2.0 ) * Difference + 105; - else if( Difference >= 60 && Difference <= 100 ) Factor = - ( 0.5 / 4.0 ) * Difference + 7.5; - } - else if ( WinningIssueRate > 20 && WinningIssueRate <= 35 ) - { - if( Difference >= 0 && Difference < 10 ) Factor = 5; - else if( Difference >= 10 && Difference < 20 ) Factor = 0.75 * Difference - 2.5; - else if( Difference >= 20 && Difference < 40 ) Factor = 12.5; - else if( Difference >= 40 && Difference < 60 ) Factor = - ( 2.5 / 4.0 ) * Difference + 37.5; - else if( Difference >= 60 && Difference <= 100 ) Factor = - ( 1.0 / 4.0 ) * Difference + 15; - } - else if( WinningIssueRate > 35 && WinningIssueRate <= 55 ) { - if( Difference >= 0 && Difference < 10 ) Factor = ( 1.0 / 1.0 ) * Difference - 5; - else if( Difference >= 10 && Difference < 20 ) Factor = 5; - else if( Difference >= 20 && Difference < 40 ) Factor = - ( 0.5 / 1.0 ) * Difference + 20; - else if( Difference >= 40 && Difference <= 100 ) Factor = - 0.25 * Difference + 10; - } - else if( WinningIssueRate > 55 ) - { - if( Difference >= 0 && Difference <= 100 ) Factor = ( 1.0 / 1.0 ) * Difference - 100; - } - - return Factor/100.0; -} - -/////////////////////////////////////////////////////////////////////////////////////////////////////// -double IssueClass::CalculateLoosingPartyRate(double WinningIssueRate, double Difference) const -{ - double Factor; - if ( WinningIssueRate <= 10 ) - { - if( Difference >= 0 && Difference < 20 ) Factor = 25; - else if( Difference >= 20 && Difference < 30 ) Factor = ( 2.5 / 1.0 ) * Difference - 25; - else if( Difference >= 30 && Difference <= 100) Factor = 50; - } - else if (WinningIssueRate > 10 && WinningIssueRate <= 20 ) - { - if( Difference >= 0 && Difference < 30 ) Factor = 25; - else if( Difference >= 30 && Difference <= 100 ) Factor = -( 2.5 / 7.0 ) * Difference + 250 / 7; - } - else if ( WinningIssueRate > 20 && WinningIssueRate <= 35 ) - { - if( Difference >= 0 && Difference < 40 ) Factor = 50; - else if( Difference >= 40 && Difference < 50 ) Factor = -( 2.5 / 1.0 ) * Difference + 150; - else if( Difference >= 50 && Difference <= 100 ) Factor = -( 0.5 / 1.0 ) * Difference + 50; - } - else if( WinningIssueRate > 35 && WinningIssueRate <= 55 ) { - if( Difference >= 0 && Difference < 20 ) Factor = 75; - else if( Difference >= 20 && Difference < 30 ) Factor = -( 2.5 / 1.0 ) * Difference + 125; - else if( Difference >= 30 && Difference < 55 ) Factor = 50; - else if( Difference >= 55 && Difference < 60 ) Factor = -5 * Difference + 325; - else if( Difference >= 60 && Difference <= 100 ) Factor = -( 2.5 / 4.0 ) * Difference + 62.5; - } - else if( WinningIssueRate > 55 ) - { - if( Difference >= 0 && Difference < 30 ) Factor = 100; - else if( Difference >= 30 && Difference < 40 ) Factor = -( 2.5 / 1.0 ) * Difference + 175; - else if( Difference >= 40 && Difference < 50 ) Factor = 75; - else if( Difference >= 50 && Difference < 60 ) Factor = -( 2.5 / 1.0 ) * Difference + 200; - else if( Difference >= 60 && Difference <= 100 ) Factor = -( 5.0 / 4.0 ) * Difference + 125; - } - - return Factor/100.0; -} - -/////////////////////////////////////////////////////////////////////////////////////////////////////// -void IssueClass::printIssueDetails() -{ - ofstream outResultFile( "result.txt", ios::app ); - cout<<"Issue "< -#include - -using namespace std; - -class IssueClass -{ - -private: - enum Party { NOPARTY, PARTY_1, PARTY_2 } IssueBelongs; - static unsigned int IssuesCnt; //<---Need this?? - double p1_rate; - double p2_rate; - double CalculateWinningPartyRate(double, double) const; - double CalculateLoosingPartyRate(double, double) const; - -public: - //IssueClass() {} - ~IssueClass() {IssuesCnt--;}//<---Need this?? - IssueClass(string INum, double m1, double m2) : - p1_rate(m1), p2_rate(m2), IssueNum(INum), IssueBelongs(NOPARTY) - { IssuesCnt++; }//<---Need this?? - void alterToSubIssue(string chldNum, double m1, double m2) { IssueNum=IssueNum+","+chldNum; p1_rate=m1; p2_rate=m2; } - double getMrkDiff() { if( p1_rate>p2_rate ) return p1_rate-p2_rate; - else return p2_rate-p1_rate; } - void setWinningParty() { if( p1_rate>p2_rate ) IssueBelongs=PARTY_1; - else IssueBelongs=PARTY_2; } - double getWiningPartyRate() { if ( IssueBelongs == PARTY_1 ) return p1_rate; - else return p2_rate; } - double getLoosingPartyRate() { if ( IssueBelongs == PARTY_1 ) return p2_rate; - else return p1_rate; } - bool Resolved() const { if (IssueBelongs==NOPARTY) return false; else return true; } - int getParty() const { /*if (IssueBelongs==NOPARTY) return 0; - else if (IssueBelongs==PARTY_1) return 1; - else return 2;*/ return IssueBelongs; } - void normalizeRates(double p1sum, double p2sum) { p1_rate=100.0*p1_rate/p1sum; p2_rate=100.0*p2_rate/p2sum; } - string getIssueNum() const { return IssueNum; } - double getP1Rate() const { return p1_rate; } - double getP2Rate() const { return p2_rate; } - - void printIssueDetails(); - void CalculateNewRates(double, double, int); - ///////////////////// - string IssueNum; -}; - - -#endif \ No newline at end of file diff --git a/main.cpp b/main.cpp deleted file mode 100644 index 8fd295f..0000000 --- a/main.cpp +++ /dev/null @@ -1,210 +0,0 @@ -#include "IssueClass.h" -#include -#include -#include -#include -#include - -using namespace std; - -void resolveIssues(vector< IssueClass >&); -void printResult(vector< IssueClass >&); -void CalculateNormRates(vector< IssueClass >&); - -int main() -{ - //////////////////////////////////////////// - // ofstream outMeta1tFile( "metadata1.txt", ios::app ); - - - vector< IssueClass > issues; - - unsigned int IssuesCnt=0; //<---Need this?? - string Inum; - double p1Rate; - double p2Rate; - - //Initial issues input - cout<<"Give Issues info, or Type '0' instate of to continue"<, then , then :"<>Inum; - //cout<<"before if"<>p1Rate; - //cout<<"after cin p1"<>p2Rate; - //cout<<"after cin p2"< or Type '0' to continue"< that should be divided"<>Inum; - if (Inum=="0") break; - - int IssueIndex=-1; - for (IssueIndex=0; IssueIndex, , then "<>childIssueNum>>p1Rate>>p2Rate; - issues[IssueIndex].alterToSubIssue( childIssueNum, p1Rate, p2Rate ); - //////////////////////// - // outMeta1tFile<<"Alter to subissue child issue name: "<, , then "<>childIssueNum; - if (childIssueNum=="0") - break; - cin>>p1Rate>>p2Rate; - IssueClass tmpIssue( parentIssueNum+","+childIssueNum, p1Rate, p2Rate ); - ////////////////////////////////////// - // outMeta1tFile<<"child issue name: "<>a; -} - -/////////////////////////////////////////////////////////////////////////////////////////////////////// -void resolveIssues(vector< IssueClass >& issues) -{ - ofstream outResultFile( "result.txt", ios::app ); - //At each iteration an Issue will be Resolved - for (unsigned int genIndex=0; genIndex < issues.size(); genIndex++) - { - double maxDiff=0; - unsigned int maxDiffIssueIndex; - - //Find an Issue to Resolve - for (unsigned int i=0; i= maxDiff ) - { - maxDiff = issues[i].getMrkDiff(); - maxDiffIssueIndex = i; - } - } - issues[maxDiffIssueIndex].setWinningParty(); //This Issue has just been resolved - cout<<"\nIssue "<& issues) -{ - ofstream outResultFile( "result.txt", ios::app ); - double p1sum=0; - double p2sum=0; - - for (unsigned int i=0; i& issues) -{ - cout<<"Results of Resolved Issues"< Date: Wed, 18 May 2016 19:30:24 +0300 Subject: [PATCH 8/8] correct input data --- src/main/resources/sql/load.sql | 42 +++++++++++++++++++++------------ src/main/webapp/script/issue.js | 1 + 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/main/resources/sql/load.sql b/src/main/resources/sql/load.sql index 85f3959..330144f 100644 --- a/src/main/resources/sql/load.sql +++ b/src/main/resources/sql/load.sql @@ -1,15 +1,27 @@ -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (1, '1', 3.4, 5.4, 0) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (2, '2', 3.4, 5.4, 0) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (3, '3', 3.4, 5.4, 0) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (4, '4', 3.4, 5.4, 0) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (5, '5', 3.4, 5.4, 0) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (6, '6', 3.4, 5.4, 0) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (7, '7', 3.4, 5.4, 0) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (8, '8', 3.2, 3.4, 0) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (9, '9', 3.2, 3.4, 0) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (10, '10', 3.2, 3.4, 0) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (11, '11', 3.2, 3.4, 0) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (12, '12', 3.2, 3.4, 0) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (13, '13', 3.5, 3.4, 0) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (14, '14', 3.2, 3.4, 0) -INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (15, '15', 3.2, 3.4, 0) \ No newline at end of file +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (1, '1', 5, 2.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (2, '2.1', 1, 2.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (3, '2.2', 2.5, 1, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (4, '2.3', 1.5, 1.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (5, '3', 2.5, 2.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (6, '4', 7.5, 5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (7, '5', 5, 5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (8, '6', 7.5, 10, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (9, '7', 5, 7.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (10, '8', 2.5, 5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (11, '9', 7.5, 5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (12, '10', 2.5, 2.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (13, '11', 5, 5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (14, '12.1', 0.5, 2.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (15, '12.2', 0.5, 1.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (16, '12.3', 2, 0.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (17, '12.4', 2, 0.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (18, '13.1', 2.5, 2.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (19, '13.2', 5, 5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (20, '14', 2.5, 5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (21, '15.1', 5, 6.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (22, '15.2', 2.5, 3.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (23, '16.1', 6.5, 5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (24, '16.2', 3.5, 2.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (25, '17', 2.5, 2.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (26, '18', 2.5, 2.5, 0) +INSERT INTO ISSUE(ID, ISSUENUM, P1RATE, P2RATE, BELONGS) VALUES (29, '19', 7.5, 5, 0) \ No newline at end of file diff --git a/src/main/webapp/script/issue.js b/src/main/webapp/script/issue.js index 3f3579c..6b50401 100644 --- a/src/main/webapp/script/issue.js +++ b/src/main/webapp/script/issue.js @@ -16,6 +16,7 @@ app.controller('issuesListController', function ($scope, $rootScope, issueServic { field: 'issueNum', displayName: 'Issue Number' }, { field: 'p1Rate', displayName: 'Party 1 Rate' }, { field: 'p2Rate', displayName: 'Party 2 Rate' }, + { field: 'belongs', displayName: 'Won by party #' }, { field: '', width: 30, cellTemplate: '' } ],