Skip to content

Commit

Permalink
Added Tenant Identifier Field in Login Activity
Browse files Browse the repository at this point in the history
  • Loading branch information
droidchef committed Nov 27, 2014
1 parent 01b4056 commit a27424f
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class LoginActivity extends ActionBarActivity implements Callback<User>{
@InjectView(R.id.et_password) EditText et_password;
@InjectView(R.id.bt_login) Button bt_login;
@InjectView(R.id.tv_constructed_instance_url) TextView tv_constructed_instance_url;
@InjectView(R.id.et_tenantIdentifier) EditText et_tenantIdentifier;
private String username;
private String instanceURL;
private String password;
Expand All @@ -72,6 +73,7 @@ public class LoginActivity extends ActionBarActivity implements Callback<User>{
private Matcher domainNameMatcher;
private Pattern ipAddressPattern;
private Matcher ipAddressMatcher;
private String tenantIdentifier;


@Override
Expand All @@ -84,6 +86,9 @@ public void onCreate(Bundle savedInstanceState) {
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
String previouslyEnteredUrl = sharedPreferences.getString(Constants.INSTANCE_URL_KEY,
getString(R.string.default_instance_url));

tenantIdentifier = sharedPreferences.getString(Constants.TENANT_IDENTIFIER_KEY,
"default");
authenticationToken = sharedPreferences.getString(User.AUTHENTICATION_KEY, "NA");

ButterKnife.inject(this);
Expand Down Expand Up @@ -141,8 +146,6 @@ public void setupUI() {

public boolean validateUserInputs() throws ShortOfLengthException {

//TODO Create All Validations Here for all input fields

String urlInputValue = et_instanceURL.getEditableText().toString();
try {
if(!validateURL(urlInputValue)) {
Expand Down Expand Up @@ -176,6 +179,9 @@ public boolean validateUserInputs() throws ShortOfLengthException {
throw new ShortOfLengthException("Password", 6);
}

if (!et_tenantIdentifier.getEditableText().toString().isEmpty()) {
API.setTenantIdentifier(et_tenantIdentifier.getEditableText().toString().trim());
}
return true;
}

Expand Down
20 changes: 14 additions & 6 deletions mifosng-android/src/main/java/com/mifos/services/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import com.mifos.objects.accounts.loan.LoanRepaymentRequest;
import com.mifos.objects.accounts.loan.LoanRepaymentResponse;
import com.mifos.objects.accounts.loan.LoanWithAssociations;
import com.mifos.objects.accounts.savings.DepositType;
import com.mifos.objects.accounts.savings.SavingsAccount;
import com.mifos.objects.accounts.savings.SavingsAccountTransactionRequest;
import com.mifos.objects.accounts.savings.SavingsAccountTransactionResponse;
import com.mifos.objects.accounts.savings.SavingsAccountWithAssociations;
Expand Down Expand Up @@ -90,6 +88,7 @@ public class API {
public static final String HEADER_MIFOS_TENANT_ID = "X-Mifos-Platform-TenantId";
//This instance has more Data for Testing
public static String mInstanceUrl = "https://demo.openmf.org/mifosng-provider/api/v1";
public static String mTenantIdentifier = "default";
public static CenterService centerService;
public static ClientAccountsService clientAccountsService;
public static ClientService clientService;
Expand All @@ -112,7 +111,7 @@ public class API {
static RestAdapter sRestAdapter;

private static synchronized void init() {
sRestAdapter = createRestAdapter(getInstanceUrl());
sRestAdapter = createRestAdapter(getInstanceUrl(), getTenantIdentifier());
centerService = sRestAdapter.create(CenterService.class);
clientAccountsService = sRestAdapter.create(ClientAccountsService.class);
clientService = sRestAdapter.create(ClientService.class);
Expand All @@ -129,13 +128,13 @@ private static synchronized void init() {
staffService = sRestAdapter.create(StaffService.class);
}

private static RestAdapter createRestAdapter(final String url) {
private static RestAdapter createRestAdapter(final String url, final String tenantIdentifier) {
RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(url)
.setRequestInterceptor(new RequestInterceptor() {
@Override
public void intercept(RequestFacade request) {
if (url.contains("developer")) {
request.addHeader(HEADER_MIFOS_TENANT_ID, "developer");
if (!tenantIdentifier.isEmpty()) {
request.addHeader(HEADER_MIFOS_TENANT_ID, tenantIdentifier);
} else {
request.addHeader(HEADER_MIFOS_TENANT_ID, "default");
}
Expand Down Expand Up @@ -208,6 +207,15 @@ public static synchronized void setInstanceUrl(String url) {
init();
}

public static synchronized String getTenantIdentifier() {
return mTenantIdentifier;
}

public static synchronized void setTenantIdentifier(String tenantIdentifier) {
mTenantIdentifier = tenantIdentifier;
init();
}

public interface CenterService {

@Headers({ACCEPT_JSON, CONTENT_TYPE_JSON})
Expand Down
2 changes: 2 additions & 0 deletions mifosng-android/src/main/java/com/mifos/utils/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class Constants {

public static String INSTANCE_URL_KEY = "instanceURL";

public static String TENANT_IDENTIFIER_KEY = "tenant identifier";

public static String PROTOCOL_HTTP = "http://";

public static String PROTOCOL_HTTPS = "https://";
Expand Down
154 changes: 116 additions & 38 deletions mifosng-android/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,126 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<EditText
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="@string/mifos"
android:textSize="30sp"
android:id="@+id/tv_title"
android:textColor="#ff003fff"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"/>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/ll_URL"
android:orientation="horizontal"
android:layout_below="@id/tv_title"
android:weightSum="4">

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/mifos_instance_domain"
android:id="@+id/tv_title_instance"
android:layout_marginLeft="10dp"
android:layout_weight="3"
/>

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/port"
android:id="@+id/tv_title_instance_port"
android:layout_marginLeft="10dp"
android:layout_weight="1"
/>

</LinearLayout>

<LinearLayout
android:id="@+id/ll_URL_INPUTS"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/et_instanceURL"
android:inputType="text"
android:hint="@string/default_instance_url"
android:minWidth="200dp"
android:imeOptions="actionNext"
android:nextFocusDown="@+id/et_username"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_below="@+id/tv_title_instance"
android:layout_centerHorizontal="true" />
android:weightSum="4"
android:orientation="horizontal"
android:layout_below="@+id/ll_URL">

<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/et_instanceURL"
android:inputType="text"
android:hint="@string/default_instance_url"
android:minWidth="200dp"
android:imeOptions="actionNext"
android:nextFocusDown="@+id/et_instancePort"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="3"
/>

<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/et_instancePort"
android:inputType="text"
android:hint="@string/default_port"
android:minWidth="200dp"
android:imeOptions="actionNext"
android:nextFocusDown="@+id/et_tenantIdentifier"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
/>
</LinearLayout>


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_constructed_instance_url"
android:layout_below="@id/et_instanceURL"
android:layout_alignLeft="@id/et_instanceURL"
android:layout_below="@id/ll_URL_INPUTS"
android:layout_alignLeft="@id/ll_URL"
android:layout_marginTop="16dp"/>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/ll_TENANT_IDENTIFIER"
android:orientation="horizontal"
android:layout_below="@id/tv_constructed_instance_url"
android:weightSum="4"
android:paddingTop="4dp">

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/tenant_identifier"
android:id="@+id/tv_tenant_identifier"
android:layout_weight="2"
/>

<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/et_tenantIdentifier"
android:inputType="text"
android:hint="@string/default_tenant"
android:minWidth="200dp"
android:imeOptions="actionNext"
android:nextFocusDown="@+id/et_username"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="2"
/>

</LinearLayout>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -46,8 +144,8 @@
android:layout_below="@+id/tv_title_username"
android:layout_alignLeft="@+id/tv_title_username"
android:layout_alignStart="@+id/tv_title_username"
android:layout_alignRight="@+id/et_instanceURL"
android:layout_alignEnd="@+id/et_instanceURL" />
android:layout_alignRight="@+id/ll_URL"
android:layout_alignEnd="@+id/ll_URL" />

<EditText
android:layout_width="wrap_content"
Expand All @@ -74,26 +172,6 @@
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="@string/mifos"
android:textSize="30sp"
android:id="@+id/tv_title"
android:textColor="#ff003fff"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/mifos_instance_domain"
android:id="@+id/tv_title_instance"
android:layout_below="@id/tv_title"
android:layout_alignLeft="@+id/et_instanceURL"
android:layout_alignStart="@+id/et_instanceURL" />

<TextView
android:layout_width="wrap_content"
Expand All @@ -102,9 +180,9 @@
android:text="@string/username"
android:id="@+id/tv_title_username"
android:layout_marginTop="16dp"
android:layout_below="@+id/tv_constructed_instance_url"
android:layout_alignLeft="@+id/et_instanceURL"
android:layout_alignStart="@+id/et_instanceURL" />
android:layout_below="@+id/ll_TENANT_IDENTIFIER"
android:layout_alignLeft="@+id/ll_TENANT_IDENTIFIER"
android:layout_alignStart="@+id/ll_URL" />

<TextView
android:layout_width="wrap_content"
Expand Down
6 changes: 5 additions & 1 deletion mifosng-android/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<string name="client">Client</string>
<string name="save">Save</string>
<string name="confirm_delete_client_image">Are you sure you want to delete this client\'s image?</string>
<string name="default_instance_url">developer.openmf.org</string>
<string name="default_instance_url">demo.openmf.org</string>
<string name="review_transaction">Review Transaction</string>
<string name="amount">Amount</string>
<string name="date">Date</string>
Expand Down Expand Up @@ -179,6 +179,10 @@
<string name="total_due">Total Due</string>
<string name="refresh">Refresh</string>
<string name="error_login_again">Please login to continue</string>
<string name="default_port">80</string>
<string name="port">Port</string>
<string name="default_tenant">default</string>
<string name="tenant_identifier">Tenant Identifier</string>


</resources>

0 comments on commit a27424f

Please sign in to comment.