Skip to content

Commit

Permalink
feat(Inventory): added option to override serial number
Browse files Browse the repository at this point in the history
  • Loading branch information
stonebuzz committed Nov 16, 2023
1 parent 65b9667 commit 90bece6
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public void onReceive(final Context context, Intent intent) {
@Override
public void onTaskSuccess(String data) {
ServerSchema model = httpInventory.setServerModel(serverName);
if(!model.getSerial().trim().isEmpty()) {
data = data.replaceAll("<SSN>(.*)</SSN>","<SSN>" + model.getSerial() + "</SSN>");
}
httpInventory.sendInventory(data, model, new HttpInventory.OnTaskCompleted() {
@Override
public void onTaskSuccess(String data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void saveServer(ArrayList<String> modelServer, Context context) {
jo.put("login", modelServer.get(2));
jo.put("pass", modelServer.get(3));
jo.put("itemtype", modelServer.get(4));
jo.put("serial", modelServer.get(5));
ArrayList<String> serverArray = preferences.loadServer();
serverArray.add(modelServer.get(0));
preferences.saveServer(serverArray);
Expand Down Expand Up @@ -94,6 +95,7 @@ public void updateServer(ArrayList<String> modelServer, String serverName, Conte
jo.put("login", modelServer.get(2));
jo.put("pass", modelServer.get(3));
jo.put("itemtype", modelServer.get(4));
jo.put("serial", modelServer.get(5));
ArrayList<String> serverArray = preferences.loadServer();
for (int i = 0; i < serverArray.size(); i++) {
if (serverArray.get(i).equals(serverName)) {
Expand Down Expand Up @@ -127,6 +129,7 @@ public void loadServer(String serverName, Context context) {
serverSchema.setLogin(jo.getString("login"));
serverSchema.setPass(jo.getString("pass"));
serverSchema.setItemtype(jo.getString("itemtype"));
serverSchema.setSerial(jo.getString("serial"));
presenter.modelServer(serverSchema);
} catch (JSONException e) {
AgentLog.e(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ public class ServerSchema {
private String login;
private String pass;
private String itemtype;
private String serial;

public String getSerial() { return this.serial; }

public void setSerial(String serial) {
this.serial = serial;
}

public String getAddress() {
return address;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ private void sendInventory() {
inventory.getXML(new InventoryTask.OnTaskCompleted() {
@Override
public void onTaskSuccess(String data) {
if(!model.getSerial().trim().isEmpty()) {
data = data.replaceAll("<SSN>(.*)</SSN>","<SSN>" + model.getSerial() + "</SSN>");
}
httpInventory.sendInventory(data, model, new HttpInventory.OnTaskCompleted() {
@Override
public void onTaskSuccess(String data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class ActivityDetailServer extends AppCompatActivity implements DetailSer
private EditText editLogin;
private EditText editPassWord;
private Spinner assetItemtype;
private EditText editSerial;
private Toolbar toolbar;
private String serverName;
private JSONObject extra_Data = null;
Expand Down Expand Up @@ -148,6 +149,10 @@ public void onClick(View view) {
editLogin.setText(extra_Data.getString("LOGIN"));
editPassWord.setText(extra_Data.getString("PASSWORD"));
assetItemtype.setSelection(((ArrayAdapter)assetItemtype.getAdapter()).getPosition(extra_Data.getString("ASSET_ITEMTYPE")));

if (extra_Data.has("ASSET_SERIAL")){
editSerial.setText(extra_Data.getString("ASSET_SERIAL"));
}
} catch (Exception ex) {
Toast.makeText(this, getApplicationContext().getResources().getString(R.string.bad_deeplink_format), Toast.LENGTH_LONG).show();
AgentLog.e(getApplicationContext().getResources().getString(R.string.bad_deeplink_format));
Expand Down Expand Up @@ -187,6 +192,10 @@ public void onActivityResult(final int requestCode, final int resultCode, final
editLogin.setText(extra_Data.getString("LOGIN"));
editPassWord.setText(extra_Data.getString("PASSWORD"));
assetItemtype.setSelection(((ArrayAdapter)assetItemtype.getAdapter()).getPosition(extra_Data.getString("ASSET_ITEMTYPE")));

if (extra_Data.has("ASSET_SERIAL")){
editSerial.setText(extra_Data.getString("ASSET_SERIAL"));
}
} catch (Exception ex) {
Toast.makeText(this, getApplicationContext().getResources().getString(R.string.bad_qr_code_format), Toast.LENGTH_LONG).show();
AgentLog.e(getApplicationContext().getResources().getString(R.string.bad_qr_code_format));
Expand Down Expand Up @@ -221,6 +230,7 @@ private void instanceObject() {
editTag = findViewById(R.id.editTag);
editLogin = findViewById(R.id.editLogin);
editPassWord = findViewById(R.id.editPassWord);
editSerial = findViewById(R.id.editSerialNumber);
actionServer.setOnClickListener(this);
deleteServer.setOnClickListener(this);
btnScan = findViewById(R.id.btnQRScan);
Expand All @@ -243,6 +253,7 @@ public void onClick(View v) {
serverInfo.add(editLogin.getText().toString());
serverInfo.add(editPassWord.getText().toString());
serverInfo.add(assetItemtype.getSelectedItem().toString());
serverInfo.add(editSerial.getText().toString());
if (serverName == null) {
presenter.saveServer(serverInfo, getApplicationContext());
//manage automatic inventory
Expand Down Expand Up @@ -300,6 +311,7 @@ public void modelServer(ServerSchema model) {
editTag.setText(model.getTag());
editLogin.setText(model.getLogin());
editPassWord.setText(model.getPass());
editSerial.setText(model.getSerial());
assetItemtype.setSelection(((ArrayAdapter)assetItemtype.getAdapter()).getPosition(model.getItemtype()));
btnScan.hide();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ private void sendInventory(final Activity activity, final Home.Presenter present
inventoryTask.getXML(new InventoryTask.OnTaskCompleted() {
@Override
public void onTaskSuccess(String data) {
AgentLog.d(data);
if(!model.getSerial().trim().isEmpty()) {
data = data.replaceAll("<SSN>(.*)</SSN>","<SSN>" + model.getSerial() + "</SSN>");
}
httpInventory.sendInventory(data, model, new HttpInventory.OnTaskCompleted() {
@Override
public void onTaskSuccess(String data) {
Expand All @@ -174,4 +176,4 @@ public void onTaskError(Throwable error) {
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public ServerSchema setServerModel(String serverName) {
serverSchema.setLogin(jo.getString("login"));
serverSchema.setPass(jo.getString("pass"));
serverSchema.setItemtype(jo.getString("itemtype"));
serverSchema.setSerial(jo.getString("serial"));
} catch (JSONException e) {
AgentLog.e(e.getMessage());
}
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/res/layout/activity_detail_server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@

</androidx.appcompat.widget.Toolbar>


<LinearLayout
android:id="@+id/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar"
android:layout_marginTop="51dp"
android:divider="@drawable/empty_tall_divider"
android:orientation="vertical"
android:padding="15dp"
android:id="@+id/linear"
android:showDividers="middle">

<EditText
Expand Down Expand Up @@ -86,8 +88,14 @@
android:id="@+id/spinnerAssetItemtype"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

<EditText
android:id="@+id/editSerialNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/serial"
android:inputType="text" />
</LinearLayout>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/btnQRScan"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<string name="login">Login</string>
<string name="password">Password</string>
<string name="tag">Tag</string>
<string name="serial">Custom asset serial</string>
<string name="tagSummary">Custom asset tag</string>
<string name="week">Week</string>
<string name="snackButton">Done</string>
Expand Down

0 comments on commit 90bece6

Please sign in to comment.