public TagModelDao(final Tag tag) { this(tag.getId(), tag.getCreatedDate(), tag.getUpdatedDate(), tag.getTagDefinitionId(), tag.getObjectId(), tag.getObjectType()); }
public Account createAccount(final LocalDate dateOfLastUnPaidInvoice) throws SubscriptionBaseApiException, AccountApiException { final UUID accountId = UUID.randomUUID(); final Account account = Mockito.mock(Account.class); Mockito.when(account.getId()).thenReturn(accountId); Mockito.when(account.getTimeZone()).thenReturn(DateTimeZone.UTC); Mockito.when(accountInternalApi.getAccountById(Mockito.eq(account.getId()), Mockito.<InternalTenantContext>any())).thenReturn(account); final Invoice invoice = Mockito.mock(Invoice.class); Mockito.when(invoice.getInvoiceDate()).thenReturn(dateOfLastUnPaidInvoice); Mockito.when(invoice.getBalance()).thenReturn(BigDecimal.TEN); Mockito.when(invoice.getStatus()).thenReturn(InvoiceStatus.COMMITTED); Mockito.when(invoice.getId()).thenReturn(UUID.randomUUID()); final InvoiceItem item = Mockito.mock(InvoiceItem.class); final List<InvoiceItem> items = new ArrayList<InvoiceItem>(); items.add(item); Mockito.when(invoice.getInvoiceItems()).thenReturn(items); final List<Invoice> invoices = new ArrayList<Invoice>(); invoices.add(invoice); Mockito.when(invoiceInternalApi.getUnpaidInvoicesByAccountId(Mockito.<UUID>any(), Mockito.<LocalDate>any(), Mockito.<InternalTenantContext>any())).thenReturn(invoices); final Tag tag = Mockito.mock(Tag.class); Mockito.when(tag.getObjectId()).thenReturn(accountId); Mockito.when(tag.getObjectType()).thenReturn(ObjectType.ACCOUNT); Mockito.when(tag.getTagDefinitionId()).thenReturn(ControlTagType.TEST.getId()); final List<Tag> tags = new ArrayList<Tag>(); tags.add(tag); Mockito.when(tagInternalApi.getTags(Mockito.eq(account.getId()), Mockito.eq(ObjectType.ACCOUNT), Mockito.<InternalTenantContext>any())) .thenReturn(tags); return account; }
@Test(groups = "slow") public void testTagCreationAndRetrieval() throws TagApiException, TagDefinitionApiException { final UUID accountId = UUID.randomUUID(); eventsListener.pushExpectedEvent(NextEvent.TAG_DEFINITION); tagDefinitionDao.create("tag1", "First tag", ObjectType.ACCOUNT.name(), internalCallContext); assertListenerStatus(); eventsListener.pushExpectedEvent(NextEvent.TAG_DEFINITION); final TagDefinitionModelDao testTagDefinition = tagDefinitionDao.create("testTagDefinition", "Second tag", ObjectType.ACCOUNT.name(), internalCallContext); assertListenerStatus(); final Tag tag = new DescriptiveTag(testTagDefinition.getId(), ObjectType.ACCOUNT, accountId, clock.getUTCNow()); eventsListener.pushExpectedEvent(NextEvent.TAG); tagDao.create(new TagModelDao(tag), internalCallContext); assertListenerStatus(); final TagModelDao savedTag = tagDao.getById(tag.getId(), internalCallContext); assertEquals(savedTag.getTagDefinitionId(), tag.getTagDefinitionId()); assertEquals(savedTag.getId(), tag.getId()); }
private boolean isTagNotIn(final ControlTagType tagType, final Tag[] tags) { for (final Tag t : tags) { if (t.getTagDefinitionId().equals(tagType.getId())) { return false; } } return true; }
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) { Tag tag = getIntent().getParcelableExtra(NfcAdapter.EXTRA_TAG); Toast.makeText(this,bin2hex(tag.getId()),Toast.LENGTH_LONG).show(); } }
public TagJson(final Tag tag, final TagDefinition tagDefinition, @Nullable final List<AuditLog> auditLogs) { this(tag.getId(), tag.getObjectType(), tag.getObjectId(), tagDefinition.getId(), tagDefinition.getName(), toAuditLogJson(auditLogs)); }
@Override public boolean apply(final Tag input) { if (objectId == null) { return objectType == input.getObjectType(); } else { return objectType == input.getObjectType() && objectId.equals(input.getObjectId()); } } }));
@Override public boolean apply(final InvoiceModelDao input) { return input.getId().equals(cur.getObjectId()); } }).orNull();
public class TagComparator implements Comparator<Tag>{ public static final String ASCENDING = "ASCENDING"; public static final String DESCENDING = "DESCENDING"; private String sortOrder; public TagComparator() { this(ASCENDING); } public TagComparator(final String sortOrder) { this.sortOrder = sortOrder; } public int compare(final Tag o1, final Tag o2) { final Comparator<Integer> comparator = new NullsLastOrderedComparator<Integer>(this.sortOrder); final int rankCompare = comparator.compare( o1.getRank(), o2.getRank() ); if( rankCompare == 0 ) { return comparator.compare( o1.getId(), o2.getId() ); } return compare; } }
Map<Integer, List<String>> tagMap = new HashMap<Integer, List<String>>(); for (AnotherTest anotherTest : anotherTests) { int id = anotherTest.getId(); for (Tag tag : tagList) { if (id == tag.getId()) { List<String> al = null; if (tagMap.containsKey(id)) { // is this `id` already populated? al = tagMap.get(id); } else { // No! Create a new List. al = new ArrayList<String>(); tagMap.put(id, al); } // Add the tag to the List. al.add(tag.getTag()); } } }
byte[] uid = tag.getId(); info[0] = "UID In Hex: " + Utils.convertByteArrayToHexString(uid) + "\n" + "UID In Dec: " + Utils.convertByteArrayToDecimal(uid) + "\n\n"; String[] techList = tag.getTechList(); String techListConcat = "Technologies: "; for(int i = 0; i < techList.length; i++) {
Assert.assertEquals(tags.get(0).getTagDefinitionId(), ControlTagType.AUTO_INVOICING_OFF.getId()); Assert.assertEquals(tags.get(0).getObjectId(), accountId); Assert.assertEquals(tags.get(0).getObjectType(), ObjectType.ACCOUNT);
private boolean isTagIn(final ControlTagType tagType, final Tag[] tags) { for (final Tag t : tags) { if (t.getTagDefinitionId().equals(tagType.getId())) { return true; } } return false; }
protected Response createTagResponse(final UUID accountId, final List<Tag> tags, final AuditMode auditMode, final TenantContext context) throws TagDefinitionApiException { final AccountAuditLogsForObjectType tagsAuditLogs = auditUserApi.getAccountAuditLogs(accountId, ObjectType.TAG, auditMode.getLevel(), context); final Map<UUID, TagDefinition> tagDefinitionsCache = new HashMap<UUID, TagDefinition>(); final Collection<TagJson> result = new LinkedList<TagJson>(); for (final Tag tag : tags) { if (tagDefinitionsCache.get(tag.getTagDefinitionId()) == null) { tagDefinitionsCache.put(tag.getTagDefinitionId(), tagUserApi.getTagDefinition(tag.getTagDefinitionId(), context)); } final TagDefinition tagDefinition = tagDefinitionsCache.get(tag.getTagDefinitionId()); final List<AuditLog> auditLogs = tagsAuditLogs.getAuditLogs(tag.getId()); result.add(new TagJson(tag, tagDefinition, auditLogs)); } return Response.status(Response.Status.OK).entity(result).build(); }
@Override public void onResume() { super.onResume(); Log.d(TAG, "onResume: action-"+getIntent().getAction()); if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(getIntent().getAction())) { Tag tag = getIntent().getParcelableExtra(NfcAdapter.EXTRA_TAG); String tagId = bytesToHexString(tag.getId()); Log.i(TAG, "NFC tag: " + tagId); } }
@Override public void write(final OutputStream output) throws IOException, WebApplicationException { try { final JsonGenerator generator = mapper.getFactory().createGenerator(output); generator.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); generator.writeStartObject(); while (iterator.hasNext()) { final Tag tag = iterator.next(); final UUID accountId = tag.getObjectId(); try { invoiceUserApi.triggerInvoiceGeneration(accountId, clock.getUTCToday(), callContext); generator.writeStringField(accountId.toString(), OK); } catch (final InvoiceApiException e) { if (e.getCode() != ErrorCode.INVOICE_NOTHING_TO_DO.getCode()) { log.warn("Unable to trigger invoice generation for accountId='{}'", accountId); } generator.writeStringField(accountId.toString(), ErrorCode.fromCode(e.getCode()).toString()); } } generator.writeEndObject(); generator.close(); } finally { // In case the client goes away (IOException), make sure to close the underlying DB connection tags.close(); } } };
public TagModelDao(final Tag tag) { this(tag.getId(), tag.getCreatedDate(), tag.getUpdatedDate(), tag.getTagDefinitionId(), tag.getObjectId(), tag.getObjectType()); }
Assert.assertEquals(tags.get(0).getTagDefinitionId(), ControlTagType.AUTO_INVOICING_OFF.getId()); Assert.assertEquals(tags.get(0).getObjectId(), accountId); Assert.assertEquals(tags.get(0).getObjectType(), ObjectType.ACCOUNT);
private boolean isAccountTaggedWith_OVERDUE_ENFORCEMENT_OFF(final InternalCallContext context) throws OverdueException { try { final UUID accountId = accountApi.getByRecordId(context.getAccountRecordId(), context); final List<Tag> accountTags = tagApi.getTags(accountId, ObjectType.ACCOUNT, context); for (final Tag cur : accountTags) { if (cur.getTagDefinitionId().equals(ControlTagType.OVERDUE_ENFORCEMENT_OFF.getId())) { return true; } } return false; } catch (final AccountApiException e) { throw new OverdueException(e); } } }
@Override public TagJson apply(final Tag tag) { final TagDefinition tagDefinition = tagDefinitionsCache.get(tag.getTagDefinitionId()); // TODO Really slow - we should instead try to figure out the account id final List<AuditLog> auditLogs = auditUserApi.getAuditLogs(tag.getId(), ObjectType.TAG, auditMode.getLevel(), tenantContext); return new TagJson(tag, tagDefinition, auditLogs); } },